-
Notifications
You must be signed in to change notification settings - Fork 114
Using url-pattern route configuration #41
Comments
Can you post some example code? I'm confused as to what you're trying to do here. |
This is also a little bit related to #39... Also, let me preface this by saying that I've not spent a huge amount of time thinking about it and there could easily be use cases that would work completely differently. Nested RoutesI wish to have a Fragment display whenever I am in route const routes = {
'/': {
title: 'Root'
},
'/home': {
title: 'Home',
auth: true
},
'/home/subhome': {
title: 'Subhome'
}
}; Currently I'd have to write my Fragment like this: <Fragment forRoutes=['/home', '/home/subhome']>
<div>
<p>Home</p>
<Fragment forRoute='/home/subhome'>
<p>Subhome</p>
</Fragment>
</div>
</Fragment> Right? It's going to get pretty tedious adding all child routes to the parent routes. What's the plan for that? When I mentioned the regex I was thinking that perhaps the way to do this was if evaluation of |
One possibility I was mulling over for nested routes was if it was possible to have a scenario where a |
This is all you should have to do to make that happen: <Fragment forRoutes=['/home', '/home/subhome']>
<p>This shows up on both /home and /home/subhome</p>
</Fragment>
|
@tptee Thanks, but that's not quite what I was getting at. In this example. There are three <Fragment forRoute='/home'>
<div>
<p>Home</p>
<Fragment forRoute='/home/sub1'>
<p>Sub1</p>
</Fragment>
<Fragment forRoute='/home/sub2'>
<p>Sub2</p>
</Fragment>
</div>
</Fragment> The only way I can see of achieving this as it stands is to do the following. Unfortunately that's not really maintainable once you have a deep and complex structure. <Fragment forRoutes=['/home', '/home/sub1', '/home/sub2']>
<div>
<p>Home</p>
<Fragment forRoute='/home/sub1'>
<p>Sub1</p>
</Fragment>
<Fragment forRoute='/home/sub2'>
<p>Sub2</p>
</Fragment>
</div>
</Fragment> Is there no way to do that at present? |
Right, there's no way to do that right now. I may explore an API to make these nested routes possible in the future. I can imagine something like: <Fragment scope='/home'>
<div>
<p>Home</p>
<Fragment forRoute='/sub1'>
<p>Sub1</p>
</Fragment>
<Fragment forRoute='/sub2'>
<p>Sub2</p>
</Fragment>
</div>
</Fragment> |
Actually, I don't think this would be a good idea. What I like about the The routes is where nesting must be configured. I do think it absolutely has to be supported ultimately though, nested routes is a basic part of any routable application. Also, it is not really that hard: #47 |
I had a look at the https://github.com/snd/url-pattern docs and that looks great, but I could not figure out how to apply this to my routes. The example I was trying to get working was a nested route. e.g. get the
Fragment
to be displayed should the url be/home
,/home/subhome
or whatever. I figured a regex would be the answer, but putting that into the routes seemed impossible as the routes are the keys. On the offchance I also tried the regex in theforRoute
of theFragment
to no avail.Split out from #35
The text was updated successfully, but these errors were encountered: