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
1

2 Answers 2

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>
Sign up to request clarification or add additional context in comments.

2 Comments

So basically you can't use vue router in a php page lets say
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?
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.