Named routes? #206
vincent-thomas
started this conversation in
Ideas
Replies: 2 comments 2 replies
-
You can give the route an id, if that's what you mean? The route's name could also conceptually be it's path relative to it's position in the router hierarchy, react-location surfaces this to you as the history pathName, |
Beta Was this translation helpful? Give feedback.
2 replies
-
You can use Router Context: // rootRoute.ts
export type AppRouterContext = {
sidebar?: FC;
};
export const rootRoute = createRootRouteWithContext<AppRouterContext>()({
component: RootLayout,
}); // MainLayout.tsx
function MainLayout() {
const route = useRouterState();
const { sidebar: Sidebar } = useRouteContext({
// eslint-disable-next-line @typescript-eslint/no-explicit-any
from: route.location.href as any,
});
return (
<div>
{Sidebar ? <div class="sidebar"><Sidebar/></div> : null}
<Outlet/>
</div>
)
} // usersRoute.ts
export const usersRoute = createRoute({
getParentRoute: () => rootRoute,
path: "users",
component: UsersPage,
context: () => ({
sidebar: UsersSidebar
})
}); like so. |
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
-
Named Routes?
Hi! Is it possible to have named routes? It would be really nice to have it implemented (if its already not) like the angular way, where you set an key to the and then put a key in the router object. Maybe this is already implemented, but i couldn't find anything in the docs, could someone please point me in the right direction?
Beta Was this translation helpful? Give feedback.
All reactions