关于vue-router的使用注意
初次使用vue-router时,发现配置了routes数组仍然无法访问配置的path。
访问时会出现ConnotGET/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' } ] } },
相关推荐
前端小白 2020-07-19
85423468 2020-07-19
bowean 2020-07-05
82344699 2020-07-05
85423468 2020-06-26
ggkuroky 2020-06-17
89711338 2020-06-14
80437700 2020-06-02
85394591 2020-05-31
80437700 2020-05-15
85394591 2020-05-15
80324291 2020-05-11
80437700 2020-05-11
85394591 2020-05-10
85423468 2020-05-05
87133050 2020-04-30
85497718 2020-04-29