Support the ongoing development of Laravel.io →
Views Laravel Mix
Last updated 2 years ago.
0

It seems to be a general misconception that you can replace routing in Laravel by routing in VueJS. Routing in Laravel is intended for your backend, while VueJS is intended for... right - your front.

So even when you decide to build a single page app (which I personally prefer over separately loading pages), you'll still need to define your routes at the backend for your API.

My setup is most of the time the same. I have one web route that serves the "container page" which boots up the single page app. Once that is done, all subsequent requests are done to the API routes. Once I authenticate a user, I'm saving the token in my vuex container, which I access in an axios interceptor to send a long to all subsequent requests. Do yourself a favour, and do not rely on sessions for single page applications; I had to learn the hard way myself, but they are not reliable (arguably because they were not designed to function in SPA setups)

And yes - I create components for my (sub)routes in VueJS, re-using generic components (a data table for instance) wherever possible.

I try to keep my VueJS routes the same as my Laravel routes just to make it easier to recognise where I need to start looking. Other than that, I think you're set to go.

If you have more precise questions, it might help posting them as well; you'll get better answers if your questions are more precise.

0

hi i suggest you have a look at Laravel Spark, built by same Laravel Author & uses Vue in a very nice way.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

ConsoleTVs consoletvs Joined 21 Jul 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.