Open seltsam23 opened 5 years ago
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
I am having the same problem of paths being accessible from other locales.
Is there any known workaround to this problem?
One workaroud I can think of is to create a global middleware that checks the current path matches the locale, and if not, redirects to the correct one:
const localePathsRedirectsOnLocalizedDomains: Middleware = ({ route, redirect, app }) => {
/* get the localized path from the current route path
if route.path === '/anmelden' but current locale is 'en' -> it will return '/login'
*/
const expectedPath = app.localePath(route.path)
// If the current path doesn't match the localized one, then we're not on the right path.
if (route.path !== expectedPath) {
// redirect to correct one
redirect(301, expectedPath)
// or send 404 page
error({ statusCode: 404 })
}
}
export default localePathsRedirectsOnLocalizedDomains
Thanks for the quick response @Kapcash . I came up with a similar solution but was manually checking the routes against the router. I didn't know about app.localePath
🙌 .
Can confirm that above workaround works.
Version
v5.3.0
Reproduction link
http://jsfiddle.com
Steps to reproduce