MaverickChan's avatar

How do i use Vue Router and normal laravel Route together

i am trying to use Vue Router with a existed lavavel project , it seems they cannot stand together.

0 likes
12 replies
KNietzsche's avatar

I have played a little with Vuetify, Vue components these last days...and I dont' use for the moment vue-router for my project...I create the template with blade...and use standard routes...but.... you can call lavarel routes from a component adding some options like that....

<v-btn   raised tag="a" href="{{ URL::route('YOURLARAVELROUTE') }}"   class="indigo--text" >
 My Button
</v-btn>

so tag="a" and href=yourLaravelRoute

that runs well for me, I asked to the https://gitter.im/vuetifyjs/Lobby chat...So I expect it is the same with your components from your Vue framework or maybe you will get some idea

KNietzsche's avatar

If in a vue component you can call a Laravel route...and you already know how to route to a Vue template....if you remove the {{ }} and replace with a laravel url...that should work too ! ok, lol...but, what do you want to know indeed ?

MaverickChan's avatar

@topvillas actually it's ok now. i wanted to make a spa within a laravel project which has lots of other normal laravel pages .Now i googled , it turns out not possible to let them live together , i tried , it is true.

topvillas's avatar
Level 46

Of course it's possible. Route all of your deep links through the root of the SPA. Then let vue-router take control.

Route::any('/spa/{all}', function () {
    return view('index');
})
->where(['all' => '.*']);
2 likes
KNietzsche's avatar

@MaverickChan cannot believe as you can call laravel routes from a component ! did it, and I have given the code ! so even if you don't use the blade template you should be able to do the same I did. Did you try ? I must say, that I was perplex when I wrote a previous post as well... After, it can depend on what you want to do ...if you want laravel policies, controllers etc That's why I wanted a mix using laravel routes, rewriting the template (really easy to do with blade) and Vuetify for my case... This discussion is interesting, let's go to the end of your problem....

KNietzsche's avatar

@topvillas tks I will try that too in the next days to understand all the cases with a complete SPA project..

nekooee's avatar

@topvillas I used this Route for all: Route::get('/{any?}', 'PanelController@index')->where('any', '.*');

But with this route, I can not do get userslist, updates, store, and delete operations. So I had to write another route before this route:

Route::resource('/users', 'UserController');
Route::resource('/articles', 'ArticleController');
Route::get('/{any?}', 'SiteController@index')->where('any', '.*');

Is this the right way? Or another solution?

Please or to participate in this conversation.