无法读取查询参数,因为 vue.js 正在将 #/ 添加到 url 的末尾
Cannot read query params becouse vue.js is adding #/ to the end of url
我在 vueJS 中有一个单页应用程序:
let router = new VueRouter({
routes: [
{ path: '/', component: Dis13HomeComponent },
{ path: '**', component: Dis13HomeComponent }
]
});
在 mounted() 的主要组件中,我得到了这样的 url 参数:
this.$route.query.token;
但是如果我打开 http://www.myapp.com/app.html?token=s56ds6d5d56f6ef6e it does not read the token parameter, becouse vue is adding #/
to the end of url so it looks like http://www.myapp.com/app.html?token=s56ds6d5d56f6ef6e#/
如果我打开 url: http://www.myapp.com/app.html#/?token=s56ds6d5d56f6ef6e 这样的格式就可以了,但是这个路径在服务器上是被禁止的。
如何读取令牌参数?
让您的路由器在 history
模式下工作,您将不再有“#”。
const router = new VueRouter({
mode: 'history', // <------------- HERE
routes: [
{ path: '/', component: Dis13HomeComponent },
{ path: '**', component: Dis13HomeComponent }
]
});
我在 vueJS 中有一个单页应用程序:
let router = new VueRouter({
routes: [
{ path: '/', component: Dis13HomeComponent },
{ path: '**', component: Dis13HomeComponent }
]
});
在 mounted() 的主要组件中,我得到了这样的 url 参数:
this.$route.query.token;
但是如果我打开 http://www.myapp.com/app.html?token=s56ds6d5d56f6ef6e it does not read the token parameter, becouse vue is adding #/
to the end of url so it looks like http://www.myapp.com/app.html?token=s56ds6d5d56f6ef6e#/
如果我打开 url: http://www.myapp.com/app.html#/?token=s56ds6d5d56f6ef6e 这样的格式就可以了,但是这个路径在服务器上是被禁止的。
如何读取令牌参数?
让您的路由器在 history
模式下工作,您将不再有“#”。
const router = new VueRouter({
mode: 'history', // <------------- HERE
routes: [
{ path: '/', component: Dis13HomeComponent },
{ path: '**', component: Dis13HomeComponent }
]
});