useRoute

The useRoute hook provides details about the current route and methods to redirect users to another location.

.url

The base URL including any hash and query parameters, eg /blog/123?foo=bar#trains.

.pathname

The path of the current URL, eg /blog/123

.hash

The hash of the current URL, eg #trains

.params

An object that includes both search params and dynamic route segment values.

Given the page routes/blog/$id.js and the url /blog/123?foo=bar, the params object would look like this:

{ id: '123', foo: 'bar' }

.search(key, value)

Updates search params in the URL. Components will render again with the updated params object.

.push(href)

Performs client-side navigation, adding the new route.

.replace(href)

Performs client-side navigation, replacing the current route with the new route.

.back()

Navigate to the previous route in the history.

.forward()

Navigate to the next route in the history.