The useParams method returns all of the path parameters that were parsed for the closest match and all of its parent matches.
The useParams hook accepts an optional options object.
import { useParams } from '@tanstack/react-router'
const routeApi = getRouteApi('/posts/$postId')
function Component() {
const params = useParams({ from: '/posts/$postId' })
// OR
const routeParams = routeApi.useParams()
// OR
const postId = useParams({
from: '/posts/$postId',
select: (params) => params.postId,
})
// OR
const looseParams = useParams({ strict: false })
// ...
}
import { useParams } from '@tanstack/react-router'
const routeApi = getRouteApi('/posts/$postId')
function Component() {
const params = useParams({ from: '/posts/$postId' })
// OR
const routeParams = routeApi.useParams()
// OR
const postId = useParams({
from: '/posts/$postId',
select: (params) => params.postId,
})
// OR
const looseParams = useParams({ strict: false })
// ...
}
Your weekly dose of JavaScript news. Delivered every Monday to over 100,000 devs, for free.