Skip to content

How to add pathname? #480

Answered by franky47
SOMONSOUM asked this question in Q&A
Jan 31, 2024 · 1 comments · 3 replies
Discussion options

You must be logged in to vote

The useQueryState(s) hooks will only update the search params on the current page, but you can render a URL from state values using createSerializer, and feed it to the router.

Your example would look like this:

import { createSerializer, parseAsInteger, parseAsStringLiteral } from 'nuqs'

// Example of search params description, which can be reused in `useQueryStates`:
const searchParamsParsers = {
  year: parseAsInteger,
  type: parseAsStringLiteral(['export', ...] as const)
}

const serialize = createSerializer(searchParamsParsers)

function MyComponent() {
  function onClick() {
    const url = serialize('/page', {
      year: 2024,
      type: 'export'
    })
    // Note that you can…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@SOMONSOUM
Comment options

@SOMONSOUM
Comment options

@franky47
Comment options

Answer selected by franky47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants