2017-04-25 127 views
4

我有用vue cli在开发模式下正常工作的项目。但是当我建立它。没有路由加载的组件('/',组件),一切都会正常进行。 什么是错在我的代码Vue路由器不能在vue cli中工作

import Vue from 'vue' 
import App from './App' 
import router from './router/index' 

Vue.config.productionTip = false 
new Vue({ 
    router, 
    template: '<App/>', 
    components: { App } 
}).$mount('#app') 

import Vue from 'vue' 
    import Router from 'vue-router' 
    import Home from '@/components/Home.vue' 
    import List from '@/components/List.vue' 
    const router = new Router({ 
    mode: 'history', 
    routes: [ 
    { 
     path: '/', 
     component: Home 
    }, 
    { 
     path: '/buy-n-sell/:category', 
     component: List, 
     children: [ 
     { 
      path: '', 
      component: catLists 
     }, 
     { 
      path: 'location/:city', 
      component: cityLists, 
      name: 'citypostList' 
     }, 
     { 
      path: 'subcategory/:subcat', 
      component: subcatList, 
      name: 'subcatpostList' 
     }, 
     { 
      path: 'subcategory/:subcat/:city', 
      component: subcatCityList, 
      name: 'subcatecityList' 
     } 
     ] 
    } 
    ] 
}) 
export default router 

回答

1

我猜你需要处理的历史模式的重写工作 检查https://router.vuejs.org/en/essentials/history-mode.html

nginx的:

location/{ 
    try_files $uri $uri/ /index.html; 
} 

阿帕奇(创建/dist/.htaccess)

<IfModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteBase/
    RewriteRule ^index\.html$ - [L] 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule . /index.html [L] 
</IfModule>