4

i have project developed with vue cli working fine in dev mode. but when i build it. everything goes fine without the components loaded by routes ('/', component). whats wrong in my code

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')

and

    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
ArK
  • 20,698
  • 67
  • 109
  • 136
Vakar
  • 81
  • 5
  • Did you found a solution? I have the same problem: https://stackoverflow.com/questions/50003678/vuejs-build-to-folder-routes-not-working – Pascut Apr 24 '18 at 14:26

2 Answers2

2

I guess you need to handle rewrites for history mode to work check https://router.vuejs.org/en/essentials/history-mode.html

nginx:

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

apache (create /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>
Can Rau
  • 3,130
  • 1
  • 23
  • 33
  • So basically you can't use vue router in a php page lets say – fpilee Aug 31 '18 at 20:37
  • you mean a php page with existing routes? I would say in either case existing routes and non-existing routes you can use vue..just depends on your setup and needs..maybe you can clarify your question? – Can Rau Aug 31 '18 at 21:26
0

in Lumen add Route::get('/{vue_capture:[/\w.-]*}', function () { return view('pages.home'); }); at the end of your web.php route file.

You might also want to check this Link on laracasts

MajidJafari
  • 1,076
  • 11
  • 15