T
TanStack2y ago
other-emerald

Display Current URL

How can I display the current URL from within a component rendered with Outlet? I've tried some of the hooks built into TanStack Router but I may be missing an import statement or misunderstanding how they work. I essentially am just trying to do "window.location.href" but through TanStack.
4 Replies
optimistic-gold
optimistic-gold2y ago
const location = useRouterState({select: (s)=>s.location)}
const location = useRouterState({select: (s)=>s.location)}
other-emerald
other-emeraldOP2y ago
do I need to import something to make useRouterState work? VS Code underlines it in red and then it wont render the page
optimistic-gold
optimistic-gold2y ago
sure you need to import it from @tanstack/react-router
other-emerald
other-emeraldOP2y ago
Many thanks 🙏

Did you find this page helpful?