简体   繁体   中英

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

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' => '.*']);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM