How to hide components on a notFound routes in TanStack Router file routes?
#6380
Unanswered
devalentineomonya
asked this question in
Q&A
Replies: 1 comment
-
|
yo! so the to hide 'em, u can check the router state directly in your const isNotFound = useRouterState({
select: (s) => s.matches.some((m) => m.routeId === '/_dashboards/$notFound'),
})
if (isNotFound) {
return <Outlet /> // just show the 404 content, skip the layout
}
return (
<SidebarProvider>
<AppSidebar ... />
<SidebarInset>
<SiteHeader />
<Outlet />
</SidebarInset>
</SidebarProvider>
)(just double-check your |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I’m using TanStack Start (file-based routing) and have a layout route that wraps multiple dashboard pages.
Here is my
route.tsxfor the/ _dashboardslayout:Problem
When a user navigates to a non-existent route inside
/ _dashboards, the Not Found page renders correctly, but the layout components:<AppSidebar /><SiteHeader />are still visible.
I tried adding a
notFoundComponentto this route:However, this does not change the behavior — the sidebar and header still render.
Expected Behavior
When a route under
/ _dashboardsis not found, I want:AppSidebarhiddenSiteHeaderhiddenNotFoundcomponent renderedQuestion
What is the recommended or idiomatic way in TanStack Router to:
Any guidance or examples would be appreciated.
Beta Was this translation helpful? Give feedback.
All reactions