Add named routes #11951
pingusama1
started this conversation in
Proposals
Add named routes
#11951
Replies: 0 comments
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.
-
Allow to name a route.
This makes applications easier to maintain.
A simplified example:
Router:
const router = createBrowserRouter([ { path:"/", element: , children: [{path:"/article",name:"listArticles",element:}, { path:"/article/:id", name:"showArticle", element:
}] } ])
ArticleList:
import { Link,useNamedRoutes } from "react-router-dom"
const articles: { id: number, title: string }[] // List of articles
const {route} = useNamedRoutes()
return (
<>
articles.map(({id,title})=><Link to={route("showArticle",{ id:id.toString() })>{title}
</>
)
I have create a pull request for that: #11945
Beta Was this translation helpful? Give feedback.
All reactions