Skip to content
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]: namespaces urls/paths #8774

Closed
GiancarlosIO opened this issue Apr 6, 2022 · 1 comment
Closed

[Feature]: namespaces urls/paths #8774

GiancarlosIO opened this issue Apr 6, 2022 · 1 comment
Labels

Comments

@GiancarlosIO
Copy link

GiancarlosIO commented Apr 6, 2022

What is the new or updated feature that you are suggesting?

I want to be able to navigate to a page/route/url by using a namespace.

Context:
In the python Django framework we have something called url-namespaces which is useful to navigate to a specific url by using only a "namespace". You can read more about it here.

I think it would be nice to have something like:

// having:
type NewRouteObject = RouteObject & { name?: string }
const routes: RouteObject[] = [{
    path: '/',
    children: [{
        index: true,
        name: 'homepage'
    }, {
        path: 'products/:productId',
        name: 'productDetail'
    }]
}]

// it would be good to be able to do:
type navigateWithNamespace = (namespace: string, parameters?: {[key: string]: string }) => void
// namespace only
navigateWithNamespace('homepage')

// namespace with path parameters
navigateWithNamespace('productDetail', { productId: '8823' })

Ideally, (and this is a tricky part) the navigateWithNamespace could be typed automatically using the react-router context data (assuming that the path/routes data lives inside the context):

type navigateWithNamespace =
  | (namespace: 'homepage') => void
  | (namespace: 'productDetail', { productId: string }) => void

Why should this feature be included?

  • Improves DX routing
  • Devs don't make mistakes/typos when trying to navigate to a page/url
  • No need to create a custom util/context/hook to make sure that the page/url/path that I wan to navigate exists

what do you think? 🤔

Thanks!

@timdorr
Copy link
Member

timdorr commented Apr 7, 2022

These are "named routes", which we used to have in the past. Because of the more dynamic nature of the current version of the library, this isn't possible and isn't something we're going to implement.

@timdorr timdorr closed this as completed Apr 7, 2022
brophdawg11 added a commit that referenced this issue Mar 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants