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

Fix trailing slash #34

Merged
merged 3 commits into from
Sep 5, 2024
Merged

Conversation

nojaf
Copy link
Contributor

@nojaf nojaf commented Sep 5, 2024

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.

Copy link

netlify bot commented Sep 5, 2024

Deploy Preview for astro-i18n-demo ready!

Name Link
🔨 Latest commit f665652
🔍 Latest deploy log https://app.netlify.com/sites/astro-i18n-demo/deploys/66d9a87eeb44190008597313
😎 Deploy Preview https://deploy-preview-34--astro-i18n-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Sep 5, 2024

Deploy Preview for astro-i18n ready!

Name Link
🔨 Latest commit f665652
🔍 Latest deploy log https://app.netlify.com/sites/astro-i18n/deploys/66d9a87e8b72aa00087df9bb
😎 Deploy Preview https://deploy-preview-34--astro-i18n.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@florian-lefebvre florian-lefebvre linked an issue Sep 5, 2024 that may be closed by this pull request
@florian-lefebvre florian-lefebvre merged commit b81d4ed into astrolicious:main Sep 5, 2024
9 checks passed
@amosbastian
Copy link

Funnily enough I think this caused #38 😆

@florian-lefebvre
Copy link
Member

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}`)
Copy link
Contributor Author

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

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.

Take trailing slash into account
3 participants