vue-router: Redirect on 404 page in google cache
Version
3.0.1
Reproduction link
[https://webcache.googleusercontent.com/search?q=cache:6OY0sSJqj5kJ:https://my-site.com/ &cd=1&hl=ru&ct=clnk&gl=ua](https://webcache.googleusercontent.com/search?q=cache:6OY0sSJqj5kJ:https://my-site.com/ &cd=1&hl=ru&ct=clnk&gl=ua)
Steps to reproduce
- open in google link site:my-site.com
- choose in search result “saved copy”
- you open page https://webcache.googleusercontent.com/search?q=cache:NugjVdqbLvoJ:https://my-site.com/ &cd=1&hl=ru&ct=clnk&gl=ua
- then page will redirect to https://my-site.com/search?cd=1&ct=clnk&gl=ua&hl=ru&q=cache%3A6OY0sSJqj5kJ%3Ahttps%3A%2F%2Fmy-site.com%2F
What is expected?
page will not redirect to the base domain
What is actually happening?
page redirected to the base domain (instead of https://webcache.googleusercontent.com/…)
- i’am trying to add something like
var router = new VueRouter({
base: window.location.pathname
...
- trying add a base tag
<base href="/">
however it’s doesnt help and the page always redirects to the base domain I found a few issues like that (“doesnt respect the <base>” and so on), but there is no certain solutions or steps to solve the problem.
(sorry, but i don’t have a permission to share my project link before release)
About this issue
- Original URL
- State: open
- Created 6 years ago
- Reactions: 19
- Comments: 22 (1 by maintainers)
Commits related to this issue
- fix(base): google cache issue: https://github.com/vuejs/vue-router/issues/2042 — committed to wkwiatek/vue-router by wkwiatek 5 years ago
- fix(base): google cache issue: https://github.com/vuejs/vue-router/issues/2042 — committed to wkwiatek/vue-router by wkwiatek 5 years ago
I’ve encountered a similar issue with my company, and I think I’ve worked out the cause. Here’s a minimal reproduction: https://github.com/dansebcar/vue-router-2042
TL;DR: looks like setting scrollBehaviour() in the VueRouter constructor can trigger an unexpected pushState when the page has a <base> tag to another origin, thereby redirecting to that origin.
For @wallbanger 's original case, I think adding the <base> tag didn’t help because google injected one above which took priority, and theirs was ignored.
In continuation of issue #3482
@posva I tried to understand what is the problem. I debug the process and noticed the problem. I think the problem is that when we open page in google web cache it has route like this
https://webcache.googleusercontent.com/search?q=cache%3A-AlwFLsePq8J%3Ahttps%3A%2F%2Fstrahovka.ru%2Fe-osago%20&cd=1&hl=ru&ct=clnk&gl=ruand like you see it has/searchroute, that is current, so$routeisundefined, because it doesn’t matched that route in route list, because we don’t have that route on our site. You can see it in this part of code. It ismatch()method inmatcher. You can see it invue-router.js:But links in web page, that represents by
RouterLinkcomponent are exist and they have valid route, so in functionisSameRoute(), that is used in render function ofRouterLinkthe process is crushed because it only checks
compareTarget(argumentbinisSameRoute()):So I think that you should also check
currentargument, because it may beundefinedlike in my exampleThis problem still happens on the newest version of nuxt