项目使用了vue router的history模式,需要
这是跳转接口
<router-link :to="{ name: 'search', params: { keyword: 'h5' }}">search</router-link>
这是路由设置
const router = new VueRouter({
base: '/destination',
mode: 'history',
routes: [
{
path: '/',
component: Index
},
{
name: 'search',
path: '/search/:keyword',
component: Search
}
]
})
这是nodejs的一些配置
app.use(require('connect-history-api-fallback')({
rewrites: [
...
{ from: /\/destination\/search/, to: '/views/destination.html'}
]
}))
跳转后的地址是
http://localhost:8080/destina...
这样我去search这个路由对应的组件可以获取router参数(h5),但是这个参数是可选的,不一定有,所有出现的可能出现两种访问接口
1、http://localhost:8080/destina...
2、http://localhost:8080/destina...
怎么去实现这个可选参数的配置呢?
const router = new VueRouter({
base: '/destination',
mode: 'history',
routes: [
]
})