-
Notifications
You must be signed in to change notification settings - Fork 64
Handle trailing slashes when prefixing routes #970
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
marinaaisa
merged 8 commits into
swiftlang:main
from
marinaaisa:trailing-slashes-routes
Oct 10, 2025
Merged
Handle trailing slashes when prefixing routes #970
marinaaisa
merged 8 commits into
swiftlang:main
from
marinaaisa:trailing-slashes-routes
Oct 10, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 tasks
AlarmedManatee
approved these changes
Oct 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
@swift-ci test |
1 similar comment
@swift-ci test |
8bec1c4
to
046a02e
Compare
AlarmedManatee
approved these changes
Oct 7, 2025
We want to split the routes into fallbackRoutes and pageRoutes to have more flexibility into how to organize the routes in our app.
The order for our routes should be: - page routes - localized page routes - fallback routes This is important because otherwise the request for localized routes will fall into the fallback routes. Before, the routes were: [ { "path": "/tutorials/:id", "name": "tutorials-overview" }, { "path": "/tutorials/:id/*", "name": "topic" }, { "path": "/documentation*", "name": "documentation-topic" }, { "path": "*", "name": "not-found", "component": {...} }, { "path": "*", "name": "server-error", "component": {...} }, { "path": "/:locale?/tutorials/:id", "name": "tutorials-overview-locale" }, { "path": "/:locale?/tutorials/:id/*", "name": "topic-locale" }, { "path": "/:locale?/documentation*", "name": "documentation-topic-locale" } ] Now they are: [ { "path": "/tutorials/:id", "name": "tutorials-overview" }, { "path": "/tutorials/:id/*", "name": "topic" }, { "path": "/documentation*", "name": "documentation-topic" }, { "path": "/:locale?/tutorials/:id", "name": "tutorials-overview-locale" }, { "path": "/:locale?/tutorials/:id/*", "name": "topic-locale" }, { "path": "/:locale?/documentation*", "name": "documentation-topic-locale" }, { "path": "*", "name": "not-found", "component": {...} }, { "path": "*", "name": "server-error", "component": {...} } ]
Pages like Not Found or Server error pages should also be localized, so we need to add them into the router's paths. Before, the routes were: [ { "path": "/tutorials/:id", "name": "tutorials-overview" }, { "path": "/tutorials/:id/*", "name": "topic" }, { "path": "/documentation*", "name": "documentation-topic" }, { "path": "/:locale?/tutorials/:id", "name": "tutorials-overview-locale" }, { "path": "/:locale?/tutorials/:id/*", "name": "topic-locale" }, { "path": "/:locale?/documentation*", "name": "documentation-topic-locale" }, { "path": "*", "name": "not-found", "component": {...} }, { "path": "*", "name": "server-error", "component": {...} } ] Now they are: [ { "path": "/tutorials/:id", "name": "tutorials-overview" }, { "path": "/tutorials/:id/*", "name": "topic" }, { "path": "/documentation*", "name": "documentation-topic" }, { "path": "/:locale?/tutorials/:id", "name": "tutorials-overview-locale" }, { "path": "/:locale?/tutorials/:id/*", "name": "topic-locale" }, { "path": "/:locale?/documentation*", "name": "documentation-topic-locale" }, { "path": "/:locale?/*", "name": "not-found-locale", "component": {...} }, { "path": "/:locale?/*", "name": "server-error-locale", "component": {...} }, { "path": "*", "name": "not-found", "component": {...} }, { "path": "*", "name": "server-error", "component": {...} } ]
Since the param locale is optional: `/:locale?/` we were repeating the pages routes in the app. Vue Router requires explicit catch-all routes for not-found handling so we need to keep the fallback routes too. [1] The new order for our routes should be: - localized page routes - localized fallback routes - fallback routes Before, the routes were: [ { "path": "/tutorials/:id", "name": "tutorials-overview" }, { "path": "/tutorials/:id/*", "name": "topic" }, { "path": "/documentation*", "name": "documentation-topic" }, { "path": "/:locale?/tutorials/:id", "name": "tutorials-overview-locale" }, { "path": "/:locale?/tutorials/:id/*", "name": "topic-locale" }, { "path": "/:locale?/documentation*", "name": "documentation-topic-locale" }, { "path": "/:locale?/*", "name": "not-found-locale", "component": {...} }, { "path": "/:locale?/*", "name": "server-error-locale", "component": {...} }, { "path": "*", "name": "not-found", "component": {...} }, { "path": "*", "name": "server-error", "component": {...} } ] Now they are: [ { "path": "/:locale?/tutorials/:id", "name": "tutorials-overview-locale" }, { "path": "/:locale?/tutorials/:id/*", "name": "topic-locale" }, { "path": "/:locale?/documentation*", "name": "documentation-topic-locale" }, { "path": "/:locale?/*", "name": "not-found-locale", "component": {...} }, { "path": "/:locale?/*", "name": "server-error-locale", "component": {...} }, { "path": "*", "name": "not-found", "component": {...} }, { "path": "*", "name": "server-error", "component": {...} }, ] [1] https://v3.router.vuejs.org/guide/essentials/dynamic-matching.html#catch-all-404-not-found-route
Improve routes order
mportiz08
approved these changes
Oct 9, 2025
@swift-ci test |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Bug/issue #161830978, if applicable:
Summary
Handle trailing slashes when prefixing routes.
We use the function
pathJoin
to make sure that we handle trailing slashes in the right way when prefixing routes.This is to prepare the router to prefix routes like
*
with a result:/:locale?/*
Dependencies
NA
Testing
Steps:
Checklist
Make sure you check off the following items. If they cannot be completed, provide a reason.
npm test
, and it succeeded