Skip to content
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

History path lost on Safari while using router.base on nuxt.config.js #2638

Closed
AvailCat opened this issue Jan 19, 2018 · 19 comments
Closed

History path lost on Safari while using router.base on nuxt.config.js #2638

AvailCat opened this issue Jan 19, 2018 · 19 comments
Assignees

Comments

@AvailCat
Copy link

AvailCat commented Jan 19, 2018

Here are steps and requirements to reproduce:

  • Any iOS device, tested on iOS11/10/9
  • Nuxt 1.1.1
  1. Install nuxt-starter-kit template
  2. Add router configure in to nuxt.config.js ↓
router: {
  base: '/abc'
}
  1. Create a.vue in pages directory, add <nuxt-link to="/b">To Page B</nuxt-link> in template
  2. Create b.vue in pages directory, add any text into template
  3. Open "http://you-host:your-port/abc/a"
  4. Press "To Page B" button, after page loaded, press the back button

Actual result: It return to "http://your-host:your-port/abc"
Excepted result: Should return to last page "http://your-host:your-port/abc/a"

This question is available on Nuxt.js community (#c2293)
@llpw4
Copy link

llpw4 commented Jan 26, 2018

I met the same problem, wish for the solution urgently;
In addition, in some android webviews(like huawei P10 own browser), If you input "http://you-host:your-port/abc/a" in the address bar, the final address will be "http://you-host:your-port/abc/" after a few seconds.
If someone met the similar problems and have had some ideas, please leave a message here

@pi0
Copy link
Member

pi0 commented Jan 26, 2018

Router base is incorrect. It should ends with a slash:
base: '/abc/'

@AvailCat
Copy link
Author

AvailCat commented Jan 27, 2018

@pi0 I have two nuxt.js project with different configure, another one using base: '/' with same problem, it works in old release or other Chromium based browser.

@llpw4
Copy link

llpw4 commented Jan 31, 2018

node_modules\nuxt\lib\app\router.js, in this file, find "createRouter" function, delete "scrollBehavior ," , and restart, and then the problem is resolved.

@zhouyu1993
Copy link

zhouyu1993 commented Feb 6, 2018

@pi0 Yes, I have the same problem. It is caused by base: '/tools/', it will write <base href="/tools/"> in <head>.

This problem is found in the IOS system.

When history.back() it will go to /tools/.

My site is https://article.cekid.com/tools/1.

Click the first tab to https://article.cekid.com/tools/1/1.

Then click your back button, it will go to https://article.cekid.com/tools/.

@LDQ-first
Copy link

@llpw4 Thanks. It works for me. I want to know the reason.

@ZooTopiaGG
Copy link

I meet the same problem. Did you solve it?

@zhouyu1993
Copy link

@ZooTopiaGG Just try to delete <base href="xxxx"> in index.html after npm run build.

@htfire
Copy link

htfire commented Jun 6, 2018

I met the same problem, wish for the solution urgently;

@y-tsuno
Copy link

y-tsuno commented Jun 8, 2018

I have same problem.
Is it difficult to behavior in a subdirectory? (or I shuold be give up "Browser Back" on Safari)

@luanwulin
Copy link

luanwulin commented Jun 14, 2018

I come out a workaround
manually add a replaceState in mounted lifecycle

       mounted(){
            // 解决ios丢失上一级url问题
            window.history.replaceState(null, null, `${this.$router.options.base}${this.$route.fullPath}`.replace(/\/\//g, '/'));
        }

this works fo me

@hqqxxf
Copy link

hqqxxf commented Jul 6, 2018

@llpw4 me too

@hqqxxf
Copy link

hqqxxf commented Jul 6, 2018

@luanwulin it must added in every page, so terrible...

@shiyuegongsui
Copy link

me too~~

@luanwulin
Copy link

@hqqxxf you may add this in default.vue

@galvez galvez self-assigned this Aug 26, 2018
@hqqxxf
Copy link

hqqxxf commented Oct 23, 2018

@luanwulin can you tell me why it(replaceState) works?

@luanwulin
Copy link

@hqqxxf sorry, i dont know either

@manniL
Copy link
Member

manniL commented Nov 24, 2018

Fixed with vuejs/vue-router#2295 / vue-router 3.0.2

@manniL manniL closed this as completed Nov 24, 2018
@lock
Copy link

lock bot commented Dec 24, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Dec 24, 2018
@danielroe danielroe added the 2.x label Jan 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests