-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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(i18n): fallback index when routing is prefix-always #9032
Conversation
|
if (i18n.routingStrategy === 'prefix-always') { | ||
// we attempt to retrieve the index page of the default locale | ||
const defaultLocaleRoutes = routesByLocale.get(i18n.defaultLocale); | ||
if (defaultLocaleRoutes) { | ||
const indexDefaultRoute = defaultLocaleRoutes.find((routeData) => { | ||
// it should be safe to assume that an index page has "index" in their name | ||
return routeData.component.includes('index'); | ||
}); | ||
if (indexDefaultRoute) { | ||
// we found the index of the default locale, now we create a root index that will redirect to the index of the default locale | ||
const pathname = '/'; | ||
const route = '/'; | ||
|
||
const segments = removeLeadingForwardSlash(route) | ||
.split(path.posix.sep) | ||
.filter(Boolean) | ||
.map((s: string) => { | ||
validateSegment(s); | ||
return getParts(s, route); | ||
}); | ||
routes.push({ | ||
...indexDefaultRoute, | ||
pathname, | ||
route, | ||
segments, | ||
pattern: getPattern(segments, config), | ||
type: 'fallback', | ||
}); | ||
} | ||
} | ||
} |
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.
This is the additional code. The rest was just moved to be like this:
if (i18n) {
// new block
if (i18n.routingStrategy === 'prefix-always') {}
if (i18n.falklback) {}
}
* fix(i18n): fallback index when routing is prefix-always * chore: add comment as per feedback
Changes
This PR fixes a case where the
routingStrategy
isprefix-always
and thesrc/pages/index.astro
isn't present.The routing strategy is pretty clear about what it does (now):
This works fine if
src/pages/index.astro
is present but it won't if the file isn't there.This PR fixes the issue in dev and SSG (SSR is already handled):
index.html
file that redirects to/en
Testing
I deleted the
src/pages/index.astro
from the fixture ofprefix-always
and the assertions should still be valid.Docs