首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Vue路由器在vue cli版本中不工作

Vue路由器在vue cli版本中不工作
EN

Stack Overflow用户
提问于 2017-04-25 14:25:12
回答 2查看 1.7K关注 0票数 4

我有项目开发与vue线索在开发模式下工作良好。但当我建造它的时候。没有路由加载的组件('/',组件),一切都很好。我的代码中有什么错误?

代码语言:javascript
运行
复制
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')

代码语言:javascript
运行
复制
    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
EN

回答 2

Stack Overflow用户

发布于 2017-05-19 17:47:46

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

nginx:

代码语言:javascript
运行
复制
location / {
    try_files $uri $uri/ /index.html;
}

apache (create /dist/.htaccess)

代码语言:javascript
运行
复制
<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteRule ^index\.html$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.html [L]
</IfModule>
票数 2
EN

Stack Overflow用户

发布于 2018-10-10 18:37:13

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

您可能还想在laracasts上检查此Link

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43603131

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档