Skip to content

Server-side rendering: redirects create duplicate pages #968

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

Closed
callumacrae opened this issue Dec 1, 2016 · 3 comments
Closed

Server-side rendering: redirects create duplicate pages #968

callumacrae opened this issue Dec 1, 2016 · 3 comments

Comments

@callumacrae
Copy link

{ path: '/from', redirect: { path: '/to' } },

When using vue-server-renderer, using a redirect in the router just sends the source of the "/to" page as if it were the "/from" page: this means that the same page can be accessed at both "/from" and "/to".

There doesn't seem to be a way to intercept it and send an HTTP redirect instead, which would be preferred, especially given that SEO is mentioned in the vue-server-renderer README!

Maybe the render stream could emit a redirect event instead, somehow?

Happy to help out, just not sure where to start.

@yyx990803
Copy link
Member

After calling router.push(context.url) in your server entry, you can check router.currentRoute.redirectedFrom to see if the result is a redirect, and return a Promise rejection with code 301/302, similar to this. You can then handle that in your stream's error event: https://github.com/vuejs/vue-hackernews-2.0/blob/master/server.js#L95-L98.

The fact that you have to do it in an error event is less-than-ideal of course, and we will think about how to improve that.

@callumacrae
Copy link
Author

Fantastic, that should do 👍

@whooooop
Copy link

If you were making an application based on hackernews, then there is a check in the file entry-server.js
line 18
if (fullPath !== url) { return reject({ url: fullPath }) }
delete these lines

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

No branches or pull requests

3 participants