You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I’m trying to access the full path of a route in my application, including cases where some parent routes are pathless (e.g., _auth/dashboard). From my understanding, there should be a way to retrieve the full path of the current route, but I couldn’t find any relevant methods or hooks in the official documentation.
What I’ve Tried:
I looked for a useRoute hook or a getFullPath method in the documentation, but these do not seem to exist in the latest version.
I explored hooks like useParams and useSearch,, but these do not provide the full path of the route, especially when dealing with pathless routes.
why do i want to get the full path with patheless route included?
answer: i want to display different component for different url instead for example i have _auth/dashboard route and i want to add sidebar if the route is under _auth how can do that
export const Route = createRootRouteWithContext<{
queryClient: QueryClient
}>()({
component: RootLayout,
})
function RootLayout() {
const location = useLocation()
const sidebarPaths = [
'/dashboard',
'/donors',
'/donors/$id', // Add dynamic route for donors
];
// Check if the current path matches any of the sidebar paths
const show_sidebar = sidebarPaths.some((path) => {
const pathPattern = new RegExp(^${path.replace(/$id/g, '[^/]+')}$);
return pathPattern.test(location.pathname);
});
function logOut() {
router.invalidate();
}
return (
<React.Fragment>
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I’m trying to access the full path of a route in my application, including cases where some parent routes are pathless (e.g., _auth/dashboard). From my understanding, there should be a way to retrieve the full path of the current route, but I couldn’t find any relevant methods or hooks in the official documentation.
What I’ve Tried:
I looked for a useRoute hook or a getFullPath method in the documentation, but these do not seem to exist in the latest version.
I explored hooks like useParams and useSearch,, but these do not provide the full path of the route, especially when dealing with pathless routes.
why do i want to get the full path with patheless route included?
answer: i want to display different component for different url instead for example i have _auth/dashboard route and i want to add sidebar if the route is under _auth how can do that
export const Route = createRootRouteWithContext<{
queryClient: QueryClient
}>()({
component: RootLayout,
})
function RootLayout() {
const location = useLocation()
const sidebarPaths = [
'/dashboard',
'/donors',
'/donors/$id', // Add dynamic route for donors
];
// Check if the current path matches any of the sidebar paths
const show_sidebar = sidebarPaths.some((path) => {
const pathPattern = new RegExp(^${path.replace(/$id/g, '[^/]+')}$);
return pathPattern.test(location.pathname);
});
function logOut() {
router.invalidate();
}
return (
<React.Fragment>
<div className={${show_sidebar ? "flex" : ""}}>
{
show_sidebar
?
:
}this way seems bad but if i can get the current path that start with _auth that would be simple
Beta Was this translation helpful? Give feedback.
All reactions