GitHub

Isomorphic Hooks

useRoute

Retrieve info about the current route or check if the current route matches some route.

Client / Server


Usage

Retrieve the route the user is currently on.

import { useRoute } from '@microeinhundert/radonis'


const route = useRoute()


console.log(route.current) // => `{ identifier: 'users.show', pattern: '/users/:id' }`

Check if a route matches the current route or a parent of the current route by identifier.

import { useRoute } from '@microeinhundert/radonis'


const route = useRoute()


console.log(route.isCurrent$('users.show')) // => `true` if currently on `users.show` or a child of `users.show`, `false` if not

Check if a route matches the current route by identifier.

import { useRoute } from '@microeinhundert/radonis'


const route = useRoute()


console.log(route.isCurrent$('users.show', { exact: true })) // => `true` if currently on `users.show`, `false` if not
Previous
useGlobals