Here are steps and requirements to reproduce:
nuxt-starter-kit templaterouter: {
base: '/abc'
}
a.vue in pages directory, add <nuxt-link to="/b">To Page B</nuxt-link> in templateb.vue in pages directory, add any text into templateActual result: It return to "http://your-host:your-port/abc"
Excepted result: Should return to last page "http://your-host:your-port/abc/a"
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.
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/.