Vakar
Vakar

Reputation: 81

Vue router not working in vue cli build

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

Upvotes: 4

Views: 1972

Answers (2)

MajidJafari
MajidJafari

Reputation: 1110

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

Upvotes: 0

Can Rau
Can Rau

Reputation: 3819

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>

Upvotes: 2

Related Questions