本页还没有译文
本页 12 段还没译成日本語,下面显示的是英文原文。useRouterState hook
还没翻译译自英文(tanstack.com)本页 12 段都还没译
The useRouterState method is a hook that returns the current internal state of the router. This hook is useful for accessing the current state of the router in a component.
Tip
If you want to access the current location or the current matches, you should try out the useLocation and useMatches hooks first. These hooks are designed to be more performant, more ergonomic and easier to use than accessing the router state directly.
useRouterState options
The useRouterState hook accepts an optional options object.
opts.select option
- Type:
(state: RouterState) => TSelected - Optional
- If supplied, this function will be called with the
RouterStateobject and the return value will be returned fromuseRouterState.
opts.structuralSharing option
- Type:
boolean - Optional
- Configures whether structural sharing is enabled for the value returned by
select. - See the Render Optimizations guide for more information.
useRouterState returns
- The current
RouterStateobject orTSelectedif aselectfunction is provided.
Examples
import { useRouterState } from '@tanstack/react-router'
function Component() {
const state = useRouterState()
// ^ RouterState
// OR
const selected = useRouterState({
select: (state) => state.location,
})
// ^ ParsedLocation
// ...
}AI 翻译查看英文原文