`
项志鹏同學
  • 浏览: 12205 次
  • 性别: Icon_minigender_1
  • 来自: 合肥
社区版块
存档分类
最新评论

关于vue-router的使用注意

 
阅读更多
初次使用vue-router时,发现配置了routes数组仍然无法访问配置的path。
访问时会出现 Connot GET /XXXX

import Vue from 'vue';
import Router from 'vue-router';
import Home from 'src@/views/Home.vue'
import FlightList from 'src@/views/FlightList.vue'

Vue.use(Router)

export default new Router({
    mode: 'history',
    base: '/',
    routes: [
        {
            path: '/',
            name: 'Home',
            component: Home
        },
        {
            path: '/index',
            component: Home
        },
        {
            path: '/flight-list',
            name: 'flightList',
            component: FlightList
        }
    ]
})

经过google后发现,vue-route使用history模式下,需要服务器后端支持,也就是后端需要为对应的请求地址返回一个html地址。因此,应该在webpack.dev.config.js中为本地服务devServer配置一个:
 devServer: {
        contentBase: './dist',
        hot: true,
        historyApiFallback: {
            rewrites: [
                { from: /^\*$/, to: '/dist/index.html' }
            ]
        }
    },
0
1
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics