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

Handle 301 redirects when alwaysRedirect is set to true #881

Closed
JosefHjorth opened this issue Sep 6, 2020 · 2 comments
Closed

Handle 301 redirects when alwaysRedirect is set to true #881

JosefHjorth opened this issue Sep 6, 2020 · 2 comments

Comments

@JosefHjorth
Copy link

I've renamed a few routes and would like to redirect the old route names to the new ones. However, since the alwaysRedirect is set to true, i18n picks up the current set locale and will add that to the route.

I've implemented the 301 at the top in the i18n middleware;

  if(route.fullPath == '/sv/old/route'){
    redirect(301, '/sv/new-route')
  }

For example;
/sv/old/route
should 301 to;
/sv/new-route

But if locale en is already set in a cookie, it will add /en/ to the route, resulting in;
/en/sv/new-route
and a page not found.

What I would like is to have the locale set to sv and the route to be respected.

I've tried to add both paths in the page view. Tried to use the setLocaleCookie right before the redirect. But can't get it to work. It still redirects again and I get the Redirected when going from "/sv/old/route" to "/sv/new-route" via a navigation guard_ error.

@rchl
Copy link
Collaborator

rchl commented Sep 8, 2020

I'm not sure exactly how you want it to work since alwaysRedirect means that it will always try to redirect to the locale stored in the cookie. And that's regardless if you have renamed some routes or not. So it basically makes switching to a route from another locale impossible unless you manually setLocale or setLocaleCookie first.

If you want me to have a closer look then you should create a simple repro.

BTW. #799 might be somewhat relevant here.

@stale
Copy link

stale bot commented Dec 6, 2020

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.

@stale stale bot added the stale label Dec 6, 2020
@stale stale bot closed this as completed Dec 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants