Skip to content

$router / useRouter()

Navigates between LAIKA pages and performs payload-aware requests.

Use $router in Vue templates or useRouter() in Composition API code. Internal links should normally use the <Link /> component.

Basic Usage

vue
<script lang="ts" setup>
import { useOctober, useRouter } from '@ratmd/laika';

const october = useOctober();
const router = useRouter();

async function openArticle(slug: string) {
    const url = october.page('blog-post', { slug });
    if (url) {
        await router.get(url);
    }
}
</script>

Available Methods

MethodDescription
visit(url, options?)Performs a LAIKA visit using the configured HTTP method.
get(url, options?)Performs a GET visit and updates browser history.
post(url, data?, options?)Performs a POST visit.
put(url, data?, options?)Performs a PUT visit.
patch(url, data?, options?)Performs a PATCH visit.
delete(url, data?, options?)Performs a DELETE visit.
raw(url, options?)Returns the raw Response without applying it as a LAIKA visit.

WARNING

raw() only performs the HTTP request. It does not update browser history, swap the current page or apply a returned LAIKA payload.

Visit Options

OptionTypeDescription
methodget, post, put, patch or deleteHTTP method used by visit() or raw().
dataobjectRequest body for non-GET requests.
replacebooleanReplaces the current history entry instead of adding one.
preserveStatebooleanPreserves the current Vue page instance while applying the response.
onlystring[]Requests only the selected payload paths.
forcebooleanAdds the X-Laika-Force request header.
requirestring[]Declares required payload paths.
headersRecord<string, string>Additional request headers.

This software is not an official OctoberCMS product and is not associated with, sponsored by, or endorsed by OctoberCMS.