Skip to content

Optional path segments #2181

@mrkamel

Description

@mrkamel

What problem is this solving

We are looking for a way to specify optional path segments in a route, like e.g.

/companies/:companyNameSlug(/page/:page)?

meaning, the /page/:page part is optional. Either the whole segment is present when the page param is present or fully not present. However, this does not seem to be possible and all my research ended without a solution. path-to-regexp (not sure if vue-router is still using it) actually supports this via curly braces

/companies/:companyNameSlug{/page/:page}?

but it seems vue-router is escaping this before handing it over when i debug it using the path ranker tool https://paths.esm.dev/

I found some example https://github.com/vuejs/vue-router/blob/dev/examples/route-matching/app.js#L24 which looks like it should be possible but this is either outdated or not correctly supported by by the path ranker tool, as the braces also get escaped and it also does not work in my app.

Thanks in advance

Proposed solution

Optimally, the curly braces would be supported to implement optional path segments

/companies/:companyNameSlug{/page/:page}?

Describe alternatives you've considered

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions