Very nested routes quirks
See original GitHub issueI’m trying to use new 3 version.
Reproduction project: https://codesandbox.io/s/svelte-spa-router-very-nested-routes-mskmc?file=/todo/Index.svelte
Questions:
-
Can we use one regex for this code in
todos/Index.svelte
?.set("/:ID", Show) .set("/:ID/*", Show);
-
Why do we need to use
const prefix = "/todos"
both intodos/Index.svelte
andtodos/Show.svelte
? Can we just useconst prefix = "/:ID"
intodos/Show.svelte
? (https://github.com/ItalyPaleAle/svelte-spa-router/issues/134) -
Can we avoid
prefix
es at all?
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
The Guide to Nested Routes with React Router - ui.dev
In this comprehensive, up-to-date guide, you'll learn everything you need to know about creating nested routes with React Router.
Read more >Adjusting rspec routing tests for nested routes - Stack Overflow
First of all, run rake routes to see what routes exist. According to what you have in your routes I would expect you...
Read more >React App Routing with Wouter — Active Links, Trailing Slash ...
We can add nested paths by setting the base path. For instance, we can write: import React from "react"; import { Link, Route,...
Read more >React Router Frequently Faced Problems - Kiprosh Blogs
Routing is one of the toughest thing to Implement in Single Page App In ... one quirk in it, Declared component if had...
Read more >React Router 6: Nested Routes - Robin Wieruch
Nested Routes are a powerful feature. While most people think React Router only routes a user from page to page, it also allows...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
First question
There was a small mistake in the regular expression I gave you. It doesn’t work unless you add
$
at the end.In
todos/Index.svelte
, your match should be (note the addition of the $ at the end of the matching sequence)Because the match is using a regexp now, as per the docs I linked above, you can’t use
params.ID
anymore as you’re doing in the file. Instead, you need to useparams[1]
(because the ID is in the first matched group).So, in
todos/Show.svelte
you also need to change:to:
Second question
As I explained above, the prefix has to be relative to the full path being matched. If you’re using a double-nested router, you still need to set
/todos
in the prefix.However, in
Show.svelte
you can set a longer prefix that includes the ID, but:prefix = /^\/todos(\/(.*))?/i
/:ID
from the route definition object inShow.svelte
, so the inner routes will NOT have access to the ID propYou’ve made it really clear now.
Thanks.