-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature]: Absolute paths in react router v6 #8848
Comments
I agree with OP, but I think a bit of context is required here. I put my routes in contants, so I can use // App.tsx
export const rootRoutes = {
settings: `settings/*`
};
return <App>
<Routes>
...
<Route path={rootRoutes['settings']} element={<SettingsPage />} />
</Routes>
</App>
/// SettingsPage.tsx
export const settingsRoutes = {...};
return <SettingsPage>
<Routes>
<Route path={settingsRoutes['user-settings']} element={<UserSettingsPage>} />
</Routes>
<SettingsPage/> The problem is that when I want to generate the path to a setting page, I want to use generatePath(settingsRoutes['user-settings']) But this path contains only the relative path. So I need to work things around : export const settingsRoute = joinRoutes(rootRoutes['settings'], { ... }); Now I have another problem. Because /// SettingsPage.tsx
const subRoutes = { ... };
export const settingsRoutes = joinRoutes(rootRoutes['settings'], subRoutes);
return <SettingsPage>
<Routes>
<Route path={subRoutes['user-settings']} element={<UserSettingsPage>} />
</Routes>
<SettingsPage/> Click to see `joinRoutes` definitionexport const joinRoutes = (rootRoute: string, routes: Record<string, string>): Record<string, string> => {
const wildcardlessRootRoute = rootRoute.replace('/*', '');
const joinedRoutes: Record<string, string> = {};
Object.entries(routes).forEach(([key, value]) => {
joinedRoutes[key] = wildcardlessRootRoute + '/' + value;
})
return joinedRoutes;
} Clearly this is a flawed way to go, as this would not support several scenarios but it works for now. |
This is already implemented. You prefix your path with
|
What is the new or updated feature that you are suggesting?
I want to use absolute path navigation in nested routes but I can't find the relevant api
The original path is /a/b/c
I wish I could render /a/b/c from url /d
Why should this feature be included?
It is risky to expose the original url directly
All components can be easily guessed by a hacker
The text was updated successfully, but these errors were encountered: