Nuxt.js: History path lost on Safari while using router.base on nuxt.config.js

Created on 19 Jan 2018  Â·  19Comments  Â·  Source: nuxt/nuxt.js

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)
documentation

Most helpful comment

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

All 19 comments

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

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

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

node_modulesnuxtlibapprouter.js, in this file, find "createRouter" function, delete "scrollBehavior ," , and restart, and then the problem is resolved.

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

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

I meet the same problem. Did you solve it?

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

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

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

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

@llpw4 me too

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

me too~~

@hqqxxf you may add this in default.vue

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

@hqqxxf sorry, i dont know either

Fixed with https://github.com/vuejs/vue-router/pull/2295 / vue-router 3.0.2

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bimohxh picture bimohxh  Â·  3Comments

vadimsg picture vadimsg  Â·  3Comments

mikekidder picture mikekidder  Â·  3Comments

maicong picture maicong  Â·  3Comments

vadimsg picture vadimsg  Â·  3Comments