Replies: 1 comment 2 replies
-
|
Interesting. You might want to review #30 as to my thoughts about such a mechanism, but I'd prefer to put that on hold until v2. You can read why in #147. To be clear: I have never thought about supporting segment parameters in Potential solution... or workaround? Don't know what you would call it: <Router id="root">
<Route key="home" path="/home">
....
</Route>
<Route key="pathWithParams" path="/:id/somepath">
{#snippet children({ rp })}
<Router id="sub-router" basePath={`/${rp?.id}/somepath`}>
<Navbar /> <!-- See Navbar code snippet below -->
<Route key="pathy" path="pathyy">
...
</Route>
<Route key="pathier" path="pathier">
...
</Route>
</Router>
{/snippet}
</Route>
</Router>This is possible because |
Beta Was this translation helpful? Give feedback.
2 replies
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.
-
Context:
Take the following code snippets:
In this scenario, we have two Routers, "root" and "sub-router". The sub router is within a route with a route parameter. Currently, there is no logic (that I can see via some quick look at the code) in RouterEngine.svelte.ts or Link.svelte to handle when the basePath contains route parameters. So, in this hypothetical scenario, when you click either of the
Linkcomponents in the browser, the literal string gets prepended to the url and location going fromhttp://localhost:3000/1234/somepath/pathytohttp://localhost:3000/:id/somepath/pathyinstead. This is a little problematic.Feature idea
The feature idea here is that the sub router can parse the basepath given to it using the same regex a route would, and can grab the parent route's route parameters list to replace the basePath dynamically. This would allow all Route components within the sub router to have access to it's parent Route's parameters, and the
prependBasePathflag on Link would prepend with the route parameters already substituted rather than using the literal basePath string.I'm planning to play around and see if I can figure out a good solution to this in the coming days. I'll update this discussion with more info/ideas as I figure things out. There might be a good solution in RouterEngine.svelte.ts to use regex to get route parameters and set them there, but maybe there is another solution within Link.svelte for this.
Beta Was this translation helpful? Give feedback.
All reactions