Mounts without a name strips the path arg from calls to child routes in url_path_for
See original GitHub issueI’m using an unnamed Mount which contains a mount to a StaticFiles instance and when using “url_for” it is unable to find the matching file. After a bit of digging it seems to be directly related to url_for_path in Mount clearing the path arg whenever the mount does not have a name set.
https://github.com/encode/starlette/blob/master/starlette/routing.py#L337
Calling url_path_for in the child router works as expected. I’m unclear as to why you’d want to strip this arg just because the mount is not named.
app.mount('/stuff', app=Router(routes=[
Mount('/static', app=StaticFiles(directory='static'), name='static'),
]))
In [6]: app.url_path_for('static', path='css/bootstap.min.css')
---------------------------------------------------------------------------
NoMatchFound
...
In [7]: app.routes[0].routes[0].url_path_for('static', path='css/bootstap.min.css')
Out[7]: '/static/css/bootstap.min.css'
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Vue router taking me to parent route mistakenly - Stack Overflow
It seems there are conflicts on your root routes (every path with "/" in front). You could check the vue-router documentation for nested ......
Read more >Ultimate React Router v6 Guide
React Router is by far the most popular routing library in React and this article goes in depth on everything you need to...
Read more >Router tutorial: tour of heroes - Angular
In this tutorial, you build upon a basic router configuration to explore features such as child routes, route parameters, lazy load NgModules, guard...
Read more >Programmatic Navigation - Vue Router
Aside from using <router-link> to create anchor tags for declarative ... the name of the route or manually specify the whole path with...
Read more >React Router v6 Preview
Relative <Route path> and <Link to>; Nested Routes and Layouts ... React Router contains many modules and hooks that you may not even...
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 FreeTop 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
Top GitHub Comments
Thanks for raising this. There’s a few seperate issues here:
url_for
was broken for the “Mount within Mount” case. Resolved in #701.I’m going to spend some more comprehensive time on this next week.
I’m also planning to start switching our docs out to use the routing table style, instead of the decorator style eg…
I think it’s a whole bunch cleaner & works better as projects grow.
That won’t mean getting rid of the decorator and
add_route
APIs, but it will mean changing the docs so that we’re pushing for that particular style, and sidelining the alternatives.+1, spent 2h debugging before I thought to check repo:issues. Documentation is also lacking on how
name
s compose in nested routing forurl_for
. This thread has more detail than the docs.