【发布时间】:2017-06-27 10:08:42
【问题描述】:
这些是我的路线:
import Search from './Search.vue'
import Home from './Home.vue'
export const routes = [
{path : '/', name: 'Home', component: Home},
{path : '/search/:keyword?', name: 'Search', component: Search}, //i put ? in the end of path to make this optional.
];
这是路由到搜索页面的操作:
this.$router.push({
name : 'Search',
params : {
keyword : this.keywords // set this to empty string
},
query: {
page : 1
}
})
如果this.keywords 是''(一个空字符串),它将返回到gamedb.com/(home)。如果this.keywords中有一些字母,路径会转到gamedb.com/search/this-is-the-keyword。
我的预期行为是当this.keywords 为空时,路径将转到gamedb.com/search。
我的console.log 显示:
[vue-router] 缺少命名路由“搜索”的参数:预期 "keyword" 匹配 "[^/]+?",但收到 ""
我不是已经在路线的尽头放了一个问号吗?我的代码有什么问题?
【问题讨论】:
标签: javascript vuejs2 vue-router