Jaeger
Jaeger

Reputation: 1754

Strange behavior between vue-router and Laravel's router

I'm building a Laravel website on which I'm using VueJS to display elements and handle the different routes, so that Laravel only load once, then leaves VueJS take control. Please keep in mind that I'm a beginner with VueJS even though I'm used to Javascript

So far, I successfully set up my routes inside VueJS, and they work: I can go from a page to another without problem.

However, I'd like to reach a page that contains a form, and since it's Laravel, I put my csrf token inside my layout's <head> as a <meta>.

Nevertheless, I keep getting errors that are the result of a lack of csrf token. When I looked at the source code, I could see that Laravel actually loaded the default 404 page, that obviously doesn't contain any csrf token.

My question is the following: how should I tell Vue or Laravel that he should let the other handle the url? Is there an other way than declare the same routes for Laravel than for VueJS?

Thank you in advance

Upvotes: 1

Views: 78

Answers (1)

ceejayoz
ceejayoz

Reputation: 180075

We use this routing rule to point all requests at the Vue app, which in our case is at example.com/app. Adjust as necessary.

Route::get('app/{any?}', function () {
    return view('app');
})->where(['any' => '.*']);

Upvotes: 1

Related Questions