Skip to content

Conversation

marinaaisa
Copy link
Member

@marinaaisa marinaaisa commented Oct 3, 2025

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:

  1. Make sure that everything continues to work as expected.

Checklist

Make sure you check off the following items. If they cannot be completed, provide a reason.

  • Added tests
  • Ran npm test, and it succeeded
  • Updated documentation if necessary

Copy link

@AlarmedManatee AlarmedManatee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@marinaaisa
Copy link
Member Author

@swift-ci test

1 similar comment
@marinaaisa
Copy link
Member Author

@swift-ci test

@marinaaisa marinaaisa requested review from AlarmedManatee and removed request for mportiz08 October 7, 2025 15:32
@marinaaisa marinaaisa force-pushed the trailing-slashes-routes branch from 8bec1c4 to 046a02e Compare October 7, 2025 15:54
marinaaisa and others added 5 commits October 7, 2025 17:46
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
@marinaaisa
Copy link
Member Author

@swift-ci test

@marinaaisa marinaaisa merged commit a8d6e85 into swiftlang:main Oct 10, 2025
1 check passed
@marinaaisa marinaaisa deleted the trailing-slashes-routes branch October 10, 2025 13:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants