-
-
Notifications
You must be signed in to change notification settings - Fork 3
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
Fix trailing slash #34
Conversation
✅ Deploy Preview for astro-i18n-demo ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
✅ Deploy Preview for astro-i18n ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Funnily enough I think this caused #38 😆 |
Yeah that's likely, if you find how to fix it I take it 😆 |
@@ -11,7 +11,7 @@ const extractLocaleFromUrl = (pathname: string) => { | |||
} else if (options.strategy === "prefixExceptDefault") { | |||
if ( | |||
locale !== options.defaultLocale && | |||
pathname.startsWith(`/${locale}/`) | |||
pathname.startsWith(`/${locale}`) |
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.
@amosbastian perhaps you can try to use
const locale = 'fr';
const regex = new RegExp(`^/${locale}(/|$|/[^/]+)`);
console.log(regex.test('/fr')); // true
console.log(regex.test('/fr/')); // true
console.log(regex.test('/fr/boo')); // true
console.log(regex.test('/freedom')); // false
instead of pathname.startsWith
Hi @florian-lefebvre, I believe I have found a fix for #24.
The problem was only ever happening on the root of a locale without a trailing slash.
F.ex.
http://localhost:4322/fr
.So I remove the trailing slash in the middleware.