Skip to content

fix: stop stripping trailing slashes in yew-router#4110

Merged
Madoshakalaka merged 3 commits intomasterfrom
fix/trailing-slash-semantics
Apr 4, 2026
Merged

fix: stop stripping trailing slashes in yew-router#4110
Madoshakalaka merged 3 commits intomasterfrom
fix/trailing-slash-semantics

Conversation

@Madoshakalaka
Copy link
Copy Markdown
Member

@Madoshakalaka Madoshakalaka commented Apr 4, 2026

Description

Stop stripping trailing slashes from route patterns and incoming URLs during matching. /path and /path/ are now distinct routes, matching standard URL semantics.

Previously, yew-router called strip_slash_suffix on both registered route patterns and incoming pathnames before matching. This made /settings and /settings/ resolve to the same route variant, but the browser resolves relative paths differently for each form (./img.jpg from /settings resolves to /img.jpg; from /settings/ resolves to /settings/img.jpg). This caused silent breakage for components that use relative asset paths.

With this change:

  • Routes defined with #[at("/settings/")] only match URLs with trailing slash
  • Routes defined with #[at("/settings")] only match URLs without trailing slash
  • Both forms can now be defined in the same enum without panicking (previously they collided after stripping)
  • The root route #[at("/")] is unaffected

Fixes #4098

Checklist

  • I have reviewed my own code
  • I have added tests

Remove `strip_slash_suffix` from route registration and matching so
`/path` and `/path/` are treated as distinct routes. This fixes
incorrect relative-path resolution in components served under
trailing-slash URLs.

BREAKING CHANGE: routes with trailing slashes now only match URLs
with trailing slashes and vice versa. Define both variants if you
need both forms to work.
github-actions[bot]
github-actions Bot previously approved these changes Apr 4, 2026
@Madoshakalaka
Copy link
Copy Markdown
Member Author

I have prepared a migration guide and will edit the website at release.

@Madoshakalaka Madoshakalaka added A-yew-router Area: The yew-router crate breaking change labels Apr 4, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 4, 2026

Visit the preview URL for this PR (updated for commit f03475f):

https://yew-rs--pr4110-fix-trailing-slash-s-5pw49jvc.web.app

(expires Sat, 11 Apr 2026 07:59:29 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

github-actions[bot]
github-actions Bot previously approved these changes Apr 4, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 4, 2026

Size Comparison

Details
examples master (KB) pull request (KB) diff (KB) diff (%)
async_clock 100.818 100.818 0 0.000%
boids 168.450 168.450 0 0.000%
communication_child_to_parent 94.076 94.076 0 0.000%
communication_grandchild_with_grandparent 105.913 105.913 0 0.000%
communication_grandparent_to_grandchild 102.256 102.256 0 0.000%
communication_parent_to_child 91.486 91.486 0 0.000%
contexts 105.977 105.977 0 0.000%
counter 86.798 86.798 0 0.000%
counter_functional 88.834 88.834 0 0.000%
dyn_create_destroy_apps 90.713 90.713 0 0.000%
file_upload 99.812 99.812 0 0.000%
function_delayed_input 94.814 94.814 0 0.000%
function_memory_game 173.667 173.667 0 0.000%
function_router 397.257 397.196 -0.061 -0.015%
function_todomvc 164.956 164.956 0 0.000%
futures 235.551 235.551 0 0.000%
game_of_life 105.099 105.099 0 0.000%
immutable 259.626 259.626 0 0.000%
inner_html 81.341 81.341 0 0.000%
js_callback 109.956 109.956 0 0.000%
keyed_list 180.408 180.408 0 0.000%
mount_point 84.714 84.714 0 0.000%
nested_list 113.657 113.657 0 0.000%
node_refs 92.089 92.089 0 0.000%
password_strength 1719.252 1719.252 0 0.000%
portals 93.558 93.558 0 0.000%
router 367.981 367.924 -0.058 -0.016%
suspense 113.965 113.965 0 0.000%
timer 88.943 88.943 0 0.000%
timer_functional 99.369 99.369 0 0.000%
todomvc 142.661 142.661 0 0.000%
two_apps 86.711 86.711 0 0.000%
web_worker_fib 136.460 136.460 0 0.000%
web_worker_prime 187.644 187.644 0 0.000%
webgl 83.485 83.485 0 0.000%

✅ None of the examples has changed their size significantly.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 4, 2026

Benchmark - SSR

Yew Master

Details
Benchmark Round Min (ms) Max (ms) Mean (ms) Standard Deviation
Baseline 10 291.439 293.320 291.869 0.541
Hello World 10 484.627 491.747 488.157 2.285
Function Router 10 31623.231 31994.519 31807.330 115.077
Concurrent Task 10 1006.700 1007.744 1007.305 0.369
Many Providers 10 1106.208 1162.122 1124.871 15.101

Pull Request

Details
Benchmark Round Min (ms) Max (ms) Mean (ms) Standard Deviation
Baseline 10 310.949 312.047 311.374 0.342
Hello World 10 474.445 481.914 478.339 3.043
Function Router 10 32982.960 34949.274 33790.126 589.412
Concurrent Task 10 1006.514 1007.993 1007.416 0.441
Many Providers 10 1081.863 1133.918 1103.531 18.391

The nested router example now defines a SettingsSlash variant for
/settings/ and redirects it to SettingsRoot
@Madoshakalaka Madoshakalaka merged commit 3b90320 into master Apr 4, 2026
36 checks passed
@Madoshakalaka Madoshakalaka deleted the fix/trailing-slash-semantics branch April 4, 2026 08:25
shan-shaji pushed a commit to shan-shaji/yew that referenced this pull request Apr 19, 2026
* fix: stop stripping trailing slashes in yew-router

BREAKING CHANGE: routes with trailing slashes now only match URLs
with trailing slashes and vice versa. Define both variants if you
need both forms to work.

* docs(website): update nested router example for trailing slash semantics

The nested router example now defines a SettingsSlash variant for
/settings/ and redirects it to SettingsRoot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-yew-router Area: The yew-router crate breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

yew-router silently strips trailing slashes, causing surprising relative-path behavior

1 participant