-
-
Notifications
You must be signed in to change notification settings - Fork 446
Description
I'm trying to rewrite non-localized paths (e.g /page1) to localized ones (/de/page1) and therefore I'm seeking help to get the following to work:
-
"/de" or "/en" should NOT be matched
-
"/de/anything" or "/en/anything" should NOT be matched
-
"/test" or "/test/anything" should be matched
-
"/deno" or "/end" should be matched
With my current implementation which is based on:
path-to-regexp/src/index.spec.ts
Line 2498 in 0c466b1
"/:test((?!login)[^/]+)", |
I can get the first 3 of 4 requierements, but can't prevent "de" from also matching "deno".
It seems like instead of allowing any chars which are not "/" after the lang segment, I would need a solution which allows either an exact match or a wilcard which must be preceded by another "/". (So both /de and /de/anything would be covered).
Segmenting these values any further is not a requierement as I'm taking req.url
as a whole and only prepend the locale.
This sandbox should probably make it easy to get what I mean:
https://codesandbox.io/s/path-to-regexp-demo-c9efk?file=/src/index.js
(Result is in the console)
I got a bit stuck here, and any help is appreciated, thank you! :)