4Catalyzer/found

Link generation and named routes

ignatevdev opened this issue · 4 comments

Hi!

Have you ever thought about giving routes a name prop, which would allow to generate a link to a particular route with an ability to substitute route params as well?

Let's say, there is a route structure like this:

<Route path="/">
    <Route path="/foo">
        <Route path="/bar/:arg" name="sample" />
    </Route>
</Route>

It would be really great if I could make a link to this route like
<Link to={{name: 'sample', params: {arg: 'baz'}}} />

This way, if I decide to change my route config with a condition to keep the name and params the same, all the links in my app would change accordingly.

This should be technically possible and I could spend some time on making a PR for this, if you could provide some guidance.

Thanks!

taion commented

Yes! We actually do this using https://github.com/4Catalyzer/found-named-routes. Haven't thought much about whether we want to pull that into core.

Oh my god, this is exactly what I wanted!

In my opinion, this feature deserves to be in the core, but even now this should be sufficient nonetheless.

Thank you!

taion commented

Well, let's add it to the README, anyway.

It's sort of nice to keep it in a separate package just because the functionality can be split out, and the versioning is somewhat disjoint, but I could be wrong here.

Okay.

Though I have stumbled upon a problem with RedirectException and named-routes middleware, I'll post a separate issue in the middleware's repository.