下面我就为大家分享一篇解决vue-router进行build无法正常显示路由页面的问题,具有很好的参考价值,希望对大家有所帮助。
使用vue cli创建一个webpack工程
加入vue-router然后使用路由引入一个新的组件。这时路由和链接是这样写的
const router = new vuerouter({
mode: 'history',
base: __dirname,
routes: [
{
path: '/first',
component: firstcom
}
]
})
<a href="/first" rel="external nofollow" >try this!</a>
1、npm run dev查看没有问题
2、npm run build打包
3、起一个服务(例如:python -m simplehttpserver)然后查看index.html页面,发现路由会请求/first页面。
4、解决的办法:将路由配置中history改为hash,将链接中/first改为/#/first。问题解决。
============2017.8.24更新================
又找了点资料发现,其实router的mode使用history是可以的。是我在做跳转的时候出现了问题。我想当然的使用了window.location.href=”“,其实应该使用router.push。代码里面的handleselect是因为使用了element ui出现的一个消息处理方法。可以理解为当按键点击时触发该方法,如果按键的key是2,那么跳转到first,key是3跳转到second。
<script>
export default {
data () {
return {
}
},
methods: {
handleselect(key, keypath) {
if (key == 2){
this.$router.push('first');
} else if (key == 3){
this.$router.push('second');
}
}
}
}
</script>
上面是我整理给大家的,希望今后会对大家有帮助。
相关文章:
javascript满天星导航栏实现方法
vue.js的computed,filter,get,set的用法及区别详解
详解从买域名到使用pm2部署node.js项目全过程
以上就是如何解决vue-router中进行build无法正常显示路由页面方面的问题(详细教程)的详细内容。