Skip to content

not respect <base > tag #1426

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
sabakugaara opened this issue May 17, 2017 · 7 comments · Fixed by #1448
Closed

not respect <base > tag #1426

sabakugaara opened this issue May 17, 2017 · 7 comments · Fixed by #1448

Comments

@sabakugaara
Copy link
Contributor

sabakugaara commented May 17, 2017

Version

2.5.3

Reproduction link

https://output.jsbin.com/yivetu/

Steps to reproduce

click the index href

What is expected?

Index url should be: https://www.example.com/

now it is: https://www.example.com/https:/www.example.com/news/index.html/

What is actually happening?

vue-router can't parse base url


This example is from the html spec about base tag https://html.spec.whatwg.org/multipage/semantics.html#the-base-element

In this example, a base element is used to set the document base URL:

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>This is an example for the &lt;base&gt; element</title>
        <base href="https://www.example.com/news/index.html">
    </head>
    <body>
        <p>Visit the <a href="archives.html">archives</a>.</p>
    </body>
</html>

The link in the above example would be a link to "https://www.example.com/news/archives.html".

If the archives's href start with /, the link would be a link to "https://www.example.com/archives" (whithout /news/) . And vue-router now doesn't support set base with: https://www.example.com/news/index.html.

some other maybe related discussions: remix-run/history#94

@sabakugaara
Copy link
Contributor Author

need some help thanks!

Search Engine's page cache will inject <base> tag for every cached page, but when I add route rule: * for 404 match, when view page cache, it will always be 404

@LinusBorg
Copy link
Member

This seems to be a feature request, not a bug report.

@sabakugaara
Copy link
Contributor Author

sabakugaara commented May 17, 2017

If modify that, it maybe a breaking change https://github.com/vuejs/vue-router/blob/dev/src/history/base.js#L194, but work right!

@posva
Copy link
Member

posva commented May 17, 2017

At the moment, you can specify base: '/news/index.html' as a workaround. Maybe we should check for starting urls when reading the base tags and strip that off with something like /^(?:https?:)?\/\/[^\/]+/

@sabakugaara
Copy link
Contributor Author

@posva thanks for your advice, in my case, I can't control the value of the base href, it was added by search engine, e.g:

vue-router page cache: https://webcache.googleusercontent.com/search?q=cache:PKjSDLmsED8J:https://github.com/vuejs/vue-router+&cd=1&hl=zh-CN&ct=clnk&lr=lang_en

in console:

console.log(document.baseURI); // output: https://github.com/vuejs/vue-router (baseURI same as base )

@posva
Copy link
Member

posva commented May 18, 2017

After searching a bit, this looks like there will be a problem with Google cache because the base tag is pointing to https://vue-hn.now.sh/top but it should be https://vue-hn.now.sh/. One fix for this is to ignore the base tag if it doesn't start with / but it may be breaking other things...

@sabakugaara
Copy link
Contributor Author

the most desirable thing is respect base tag and work well, I would like to submit a PR for this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants