Remove the trailiing slash from a base_path'd router's root URL #2395
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently, given a Dioxus.toml with
base_path = "base/path"
, navigating to e.g.localhost:8080/base/path
will result in the router pushing/base/path/
to the web history API, and therefore renderinglocalhost:8080/base/path/
in the browser address bar. This PR attempts to remove the trailing slash from the root url ofbase_path
'd routers without breaking the functionality of apps that do not specify abase_path
.This isn't a functional bug, but it's a peeve of mine, and I wanted to figure out why this was happening. Additionally, this behavior is inconsistent with
.nest("/base/path", MyDioxusMethodRouter)
will result in browsers rendering e.g.localhost:8080/base/path/
as the root of the dioxus app, but might cause direct navigations tolocalhost:8080/base/path/
to 404. (NB. this is probably an issue with nested fallbacks in axum, but it was very frustrating for me while I was figuring that out.)#[route("/not/home/")]
(note the trailing slash) will let bothlocalhost:8080/base/path/not/home
(note the not trailing slash) andlocalhost:8080/base/path/not/home/
to resolve tolocalhost:8080/base/path/not/home
(again, note the lack of trailing slash).I'm opening this as a draft because I am not at all confident in the implementation. The fundamental change is displaying the root URL of routers as
""
rather than"/"
. This might be a bad idea. As you can see from the modified tests, this change requires special-case'ingLink
s that direct to the root url for non-base_path
'd apps. Seeinghref=""
in an<a>
is... kinda weird. Maybe a bit of a red flag.WebHistory::full_path
does correctly resolve that to"/"
before pushing to the history API, but I've not tested this behavior with liveview or native apps, nor have I tested this change with routers that use the#[layout(...)]
or#[nest(...)]
features.I'm planning on building some axum experiments with this change in place, so I may update the PR as I find issues. If there's no additional movement on this PR from myself or the dioxus team in, idk, a few weeks I'll probably close this PR to keep it from taking up space.