export default new Router({
mode: 'history', //去掉#
routes: [
{
path: '/apple',
name: 'Apple',
component: Apple
},
]
})
vue-router
默认 hash 模式 ——
使用 URL 的 hash 来模拟一个完整的 URL,于是当 URL 改变时,页面不会重新加载。
因为对于正常的页面来说,更换url一定是会导致页面的更换的,
而只有更换url中的查询字符串和hash值得时候才不会重新加载页面
需要加一个错误页面,防止匹配不到资源的时候出现404
export default new Router({
mode: 'history',
routes: [
{ path: '*',
component: NotFoundComponent
}
]
})
看看这篇文章 有时间再看,小白现在表示看不太懂 路由的两种模式