Skip to content
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

"path must be" (regex) syntax in v8 (i18n/localization) #349

Closed
samuelstroschein opened this issue Feb 13, 2025 · 2 comments
Closed

"path must be" (regex) syntax in v8 (i18n/localization) #349

samuelstroschein opened this issue Feb 13, 2025 · 2 comments

Comments

@samuelstroschein
Copy link

samuelstroschein commented Feb 13, 2025

Hi there,

I am wondering how path-to-regexp would support matching paths "only if" or whether I need to adopt URLPattern.

Use case i18n

I need a pattern that matches localized URLs.

https://example.com/page -> en
https://example.com/de/page -> de

The pattern I came up with "http{s}\\://:domain/{:locale}{/*path}" (correctly) matches anything as :locale. Hence, https://example.com/page is matched as parameters: { locale: page }, which is incorrect. The desired locale parameter should be undefined.

In old path-to-regexp <8 and URLPattern, regex helps establish the desired behavior (try it out yourself).

http{s}?://:domain.:tld/:locale(de)?/:path*
@samuelstroschein samuelstroschein changed the title negation syntax in v8 (i18n/localization) path must be syntax in v8 (i18n/localization) Feb 13, 2025
@samuelstroschein samuelstroschein changed the title path must be syntax in v8 (i18n/localization) "path must be" (regex) syntax in v8 (i18n/localization) Feb 13, 2025
@samuelstroschein
Copy link
Author

I decided to adopt URLPattern now that it has become the standard for the web.

@samuelstroschein samuelstroschein closed this as not planned Won't fix, can't repro, duplicate, stale Feb 15, 2025
@blakeembrey
Copy link
Member

Sounds good. URLPattern is based off the v6 syntax of this library anyway so it should be a smooth transition for you.

In v8 there currently isn't regex support due to time constraints, but it would actually be fairly simple to add what you're asking for specifically (i.e. a limited subset of regex support). I'll leave this closed since you've resolved your issue, but it is on my backlog to add regex support back so you can write :locale(de|en) again.

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

No branches or pull requests

2 participants