vue-router icon indicating copy to clipboard operation
vue-router copied to clipboard

Redirect on 404 page in google cache

Open wallbanger opened this issue 7 years ago • 22 comments

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


  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)

wallbanger avatar Feb 02 '18 11:02 wallbanger

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 🙂

posva avatar Feb 02 '18 11:02 posva

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.

jasonhibbs avatar Mar 21 '18 17:03 jasonhibbs

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.

GMory avatar Jul 11 '18 17:07 GMory

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

paullombard avatar Aug 16 '18 16:08 paullombard

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)

TheAlexLichter avatar Nov 01 '18 15:11 TheAlexLichter

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.

dansebcar avatar Jun 19 '19 15:06 dansebcar

This problem still happens on the newest version of nuxt

ghost avatar Jan 29 '21 02:01 ghost

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 avatar Mar 16 '21 16:03 VsevolodChumachenko

@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

VsevolodChumachenko avatar Apr 09 '21 17:04 VsevolodChumachenko

The problem is still there.

suinly avatar Jul 02 '21 08:07 suinly

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

Kolobok12309 avatar Aug 03 '21 18:08 Kolobok12309

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.

gaisinskii avatar Apr 07 '22 13:04 gaisinskii

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.

eduardmavliutov avatar Aug 10 '22 14:08 eduardmavliutov

+1

zimiovid avatar Aug 10 '22 15:08 zimiovid

+1

Andr-07 avatar Aug 10 '22 15:08 Andr-07

+1

ekho avatar Aug 10 '22 15:08 ekho

+1

argo-qu avatar Aug 10 '22 17:08 argo-qu

+1

Ann2827 avatar Aug 11 '22 09:08 Ann2827

+1

asifkhanpathan avatar Oct 06 '22 18:10 asifkhanpathan

+1 on our Nuxt application

LegendSebastiano-L avatar Jan 27 '23 10:01 LegendSebastiano-L

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

TheAlexLichter avatar Feb 11 '23 15:02 TheAlexLichter

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

s547926509s avatar Jan 10 '24 10:01 s547926509s