Home  >  Q&A  >  body text

Unable to achieve path jump of vue-router

<p>So when I'm on the home page (http://127.0.0.1:8000/) I get the correct components I set in the vue-router file, but whenever I go to http://127.0 .0.1:8000/dashboard, it shows me a 404 error and I really don't know why. The path to the component is correct</p> <p><strong>This is my vue-router file:</strong></p> <pre class="brush:php;toolbar:false;">import Vue from 'vue' import VueRouter from 'vue-router' Vue.use(VueRouter) import loginPage from '../Pages/loginPage' import dashboard from '../Pages/dashboard' const router = new VueRouter({ mode: 'history', routes: [ { path: '/', name: 'login', component: loginPage }, { path: '/dashboard', name: 'dashboard', component: dashboard, }, ], }); export default router;</pre> <p><strong>This is my app.js file</strong></p> <pre class="brush:php;toolbar:false;">import Vue from 'vue'; import index from './Index.vue' import VueRouter from 'vue-router' Vue.use(VueRouter) import router from './router'; import axios from 'axios'; import VueAxios from 'vue-axios'; window.Vue = require('vue').default; newVue({ router, render: h => h(index), }).$mount('#app')</pre> <p><strong>This is the index.vue file (where I display the component when the link changes)</strong></p> <pre class="brush:php;toolbar:false;"><template> <div class="aa"> <p>hallo world</p> <router-view/> </div> </template> <script> export default { mounted() { console.log('Component hoi.') } } </script></pre>
P粉101708623P粉101708623415 days ago401

reply all(1)I'll reply

  • P粉834840856

    P粉8348408562023-08-31 14:27:57

    If you are using Laravel Vue, you must check if you are passing the route

    Route::get('/{any}', function () {
      return view('welcome');
    })->where('any','.*')->name('vue')

    reply
    0
  • Cancelreply