控制台中显示警告:
the id param was not provided.
文档提到将使用当前路由:
current is the current Route by default (most of the time you don't need to change this)
html代码:
<div id="app">
<router-link to="/5">/5</router-link>
<button @click="onClick">Resolve</button>
</div>
js代码:
new Vue({
el: '#app',
router: new VueRouter({
routes: [
{
name: 'foo',
path: '/:id',
component: {
template: '<div>Foo <router-view/></div>',
},
children: [
{
name: 'bar',
path: 'bar',
component: {
template: '<div>Bar</div>'
}
}
]
},
],
}),
methods: {
onClick() {
console.log('Omitting current');
this.$router.resolve({ name: 'bar' });
console.log('Including current');
this.$router.resolve({ name: 'bar' }, this.$route);
}
}
});
最佳答案
我知道这已经过期了,但我会分享我的发现。
当你调用$router.resolve()
时,它使用vue-router/src/util/location.js
的normalizeLocation()
获取 Location
对象。
您可以看到 current?
选项仅用于解析相对路径。
current.params
包含在新的 Location
中的唯一情况是给定的 RawLocation
是相对的,并且包含 参数
本身。
关于vue.js - VueJS : router. 解决问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53712990/