Skip to content

Redirect on 404 page in google cache #2042

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

Open
wallbanger opened this issue Feb 2, 2018 · 22 comments
Open

Redirect on 404 page in google cache #2042

wallbanger opened this issue Feb 2, 2018 · 22 comments

Comments

@wallbanger
Copy link

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

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/...)


  1. i'am trying to add something like
var router = new VueRouter({
          base: window.location.pathname
          ...
  1. 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 " 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)

@posva
Copy link
Member

posva commented Feb 2, 2018

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 🙂

@jasonhibbs
Copy link

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.

@GMory
Copy link

GMory commented Jul 11, 2018

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.

@paullombard
Copy link

@jasonhibbs - were you able to get to the bottom of this? I see your example's home page is cached nicely now.

@TheAlexLichter
Copy link

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)

@vuejs vuejs deleted a comment from gautiermorel Feb 11, 2019
@dansebcar
Copy link

dansebcar commented Jun 19, 2019

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 tag to another origin, thereby redirecting to that origin.

For @wallbanger 's original case, I think adding the tag didn't help because google injected one above which took priority, and theirs was ignored.

@ghost
Copy link

ghost commented Jan 29, 2021

This problem still happens on the newest version of nuxt

@VsevolodChumachenko
Copy link

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

@VsevolodChumachenko
Copy link

@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!

Снимок экрана 2021-04-09 в 20 42 29

Снимок экрана 2021-04-09 в 20 42 35

Снимок экрана 2021-04-09 в 20 42 49

@suinly
Copy link

suinly commented Jul 2, 2021

The problem is still there.

@Kolobok12309
Copy link

Kolobok12309 commented Aug 3, 2021

Mb it help someone fix for nuxtjs and add abstract routing
gist
vue-router-webcache

@gaisinskii
Copy link

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.

@eduardmavliutov
Copy link

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.

Have the same story!
Hope the fix is on the way.

@zimiovid
Copy link

+1

5 similar comments
@Andr-07
Copy link

Andr-07 commented Aug 10, 2022

+1

@ekho
Copy link

ekho commented Aug 10, 2022

+1

@argo-qu
Copy link

argo-qu commented Aug 10, 2022

+1

@Ann2827
Copy link

Ann2827 commented Aug 11, 2022

+1

@asifkhanpathan
Copy link

+1

@LegendSebastianoL
Copy link

+1 on our Nuxt application

@TheAlexLichter
Copy link

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

@s547926509s
Copy link

@gaisinskii It seems that I have also encountered this problem with nuxt2. Google cache directly jumps to 404. How did you solve it before?

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