2

I followed this tutorial https://laraveldaily.com/quick-start-laravel-5-5-vue-js-simple-crud-project/

However when I load : localhost/admin/companies , I get page not found .

I tried to change to this too

const router = new VueRouter({
 routes: [
   { path: '/admin/companies', component: CompaniesController }
 ]
})

But I get "Syntax error { " on the part VueRouter({ which I don't understand why. Can anyone help?

Thanks!

2
  • It is not laravel error. Looks like you made syntax mistake on your Vue code. Let me see your full code. Commented Aug 2, 2018 at 3:28
  • @Ts8060 Which section would you like to take a look? I will add on above. I changed my route to Route::get('/admin/companies', 'Api\V1\CompaniesController@index'); and it works. Not sure why the above using VueRouter not working. Commented Aug 2, 2018 at 3:46

2 Answers 2

1

Vue Router doesn't reload the page. Vue Router doesn't work like the Laravel Router. All it does whenever a Vue route changes, it mounts different component to a specific area. This area is defined by predefined router-view element. It mounts the component according to the Vue route changes.

Blade

<div class='box'>
    <router-view name="content-viewport"></router-view>
</div>

Vue

const router = new VueRouter({
  routes: [
    { path: '/admin/companies', components: {"content-viewport" : CompaniesController} }
  ]
});

Now when you go to domain#/admin/companies Vue will mount the component CompaniesController in 'content-viewport'

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you ! Managed to solve this but you gave the solution I needed.
0

In Vue js <router-link use to navigate the page from vue side.

In route, file route define here.

const router = new VueRouter({

  routes: [
    { path: '/admin/companies', redirect: { name: 'CompaniesController' } },
  ],
})


<router-link to="/about">Go</router-link>

Then call localhost/admin/companies then the page will load.

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.