Vue路由器无法在vue cli build

时间:2017-04-25 06:25:12

标签: vuejs2 vue-router

我开发的项目使用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

2 个答案:

答案 0 :(得分:1)

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

nginx的:

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

apache(创建/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>

答案 1 :(得分:0)

在流明中

Route::get('/{vue_capture:[/\w.-]*}', function () { return view('pages.home'); });路径文件的末尾添加web.php

您可能还想在播客中查看此Link