我下载了VUE的脚手架。
npm install vue-cli
安装部署好后:
在浏览器输入:http://localhost:8080/
显示出来的跟文档的一样。
现在我新建一个页面:'../../static/testhello/index.vue',
我的期望是输入地址就能显示该页面:http://localhost:8080/testhello
可是刷新页面没有反应,这个页面一直出不来。非得输入:http://localhost:8080/#/testhello
这是为什么得多个#号?我非常疑惑。于是查阅了下资料,才懂得:
#这个是hash路由(默认路由);
/这个是histroy路由(切换路由)。
要修改为切换路由,不用#这个,需要添加
mode: 'history',
全面代码如:
export default new Router({
mode: 'history',//必加 路由模式:hash(默认),history模式
linkActiveClass: 'active'// 修改路由高亮样式,默认值为'router-link-active'
//路由规则
routes:[
{
path:'/',
name:'index',
component:'Index'
}
],
})