vue-router
vue-router copied to clipboard
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%20
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
(sorry, but i don't have a permission to share my project link before release)
There was #1426. The PR fixing it was reverted because it was breaking other stuff but it should be working. We will need a minimal repro. It can be a simple HTML page with some script tags. I don't know Google cache so I'll appreciate you add anything necessary for that to work too 🙂
Think I’m in the same boat, as my site also gets redirected. Not sure how we can repro since we’re dealing with Google’s cache, but here’s a link to the Google Search Result, a link to the Google Cached Site, and to the site itself.
I’ve since added a base tag after reading other issues, too, but since we’re dealing with Google’s cached copy, I’m guessing that won’t take effect for a while, even if it is a fix.
Encountering the same issue. @jasonhibbs judging by those links, it looks like the base tag fix isn't a fix huh? The delay on seeing whether something works makes troubleshooting this pretty painful.
@jasonhibbs - were you able to get to the bottom of this? I see your example's home page is cached nicely now.
Info: Issue is still present.
It seems that the base URL is changed after accessing the cached content (Example: https://webcache.googleusercontent.com/search?q=cache:LuVRWZm_yMAJ:https://pass.wurd.it/ -> https://pass.wurd.it/search?q=cache%3ALuVRWZm_yMAJ%3Ahttps%3A%2F%2Fpass.wurd.it%2F)
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
For @wallbanger 's original case, I think adding the
This problem still happens on the newest version of nuxt
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=ru and like you see it has /search route, that is current, so $route is undefined, 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 is match() method in matcher. You can see it in vue-router.js:
...
} else if (location.path) {
location.params = {};
for (var i = 0; i < pathList.length; i++) {
var path = pathList[i];
var record$1 = pathMap[path];
if (matchRoute(record$1.regex, location.path, location.params)) {
return _createRoute(record$1, location, redirectedFrom)
}
}
}
// no match
return _createRoute(null, location)
But links in web page, that represents by RouterLink component are exist and they have valid route, so in function isSameRoute(), that is used in render function of RouterLink
classes[exactActiveClass] = isSameRoute(current, compareTarget); // current is undefined but compareTarget not
the process is crushed because it only checks compareTarget (argument b in isSameRoute()):
function isSameRoute (a, b) {
if (b === START) {
return a === b
} else if (!b) {
return false
} else if (a.path && b.path) {
return (
a.path.replace(trailingSlashRE, '') === b.path.replace(trailingSlashRE, '') &&
a.hash === b.hash &&
isObjectEqual(a.query, b.query)
)
} else if (a.name && b.name) {
return (
a.name === b.name &&
a.hash === b.hash &&
isObjectEqual(a.query, b.query) &&
isObjectEqual(a.params, b.params)
)
} else {
return false
}
}
So I think that you should also check current argument, because it may be undefined like in my example
@manniL
About 404 on NUXT applications. After debugging the process I've noticed when nuxt tries to render page on client side it checks is the page view on the same route with currentRoute (isSamePath(NUXT.routePath, _app.context.route.path)). After that it understands that route of page view isn't the same with path in URL, so it tries to find the page with path in URL and fails because there isn't the view with that route.
For example in GoogleWebCache we open the page with view path https://my-site.com/, so full path would be like this https://webcache.googleusercontent.com/search?q=cache:7uwnHa1kNEsJ:https://my-site.com/+&cd=1&hl=ru&ct=clnk&gl=ru. So we see that view path is / and path in URL is /search. After trying to render /search page it fails and renders the error layout page (404). I added some screenshots, where it happens. I would like to find this rows in source code, but compiled code is very different, so I managed to find only checking the routes isSamePath(NUXT.routePath, _app.context.route.path). I hope this information will be enough to solve the problem. Thank you!
The problem is still there.
Mb it help someone fix for nuxtjs and add abstract routing gist vue-router-webcache
Bumping, the problem is still here. Having it on my NuxtJS projects, when redirecting from a cached page router is trying to resolve search page that does not exist and this results in 404. This solution probably fixes the problem or @Kolobok12309 `s one, but still looking for a proper fix.
Bumping, the problem is still here. Having it on my NuxtJS projects, when redirecting from a cached page router is trying to resolve
searchpage that does not exist and this results in 404. This solution probably fixes the problem or @Kolobok12309 `s one, but still looking for a proper fix.
Have the same story! Hope the fix is on the way.
+1
+1
+1
+1
+1
+1
+1 on our Nuxt application
I can't reproduce this with a Nuxt3 application anymore. e.g. https://webcache.googleusercontent.com/search?q=cache:-NtU2cJakY8J:https://www.lichter.io/&cd=2&hl=en&ct=clnk&gl=nl resolves fine and does not redirect
@gaisinskii It seems that I have also encountered this problem with nuxt2. Google cache directly jumps to 404. How did you solve it before?