简体   繁体   English

vue-router 和 Laravel 的路由器之间的奇怪行为

[英]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.我正在构建一个 Laravel 网站,在该网站上我使用 VueJS 来显示元素并处理不同的路由,以便 Laravel 只加载一次,然后让 VueJS 进行控制。 Please keep in mind that I'm a beginner with VueJS even though I'm used to Javascript请记住,我是 VueJS 的初学者,尽管我已经习惯了 Javascript

So far, I successfully set up my routes inside VueJS, and they work: I can go from a page to another without problem.到目前为止,我成功地在 VueJS 中设置了我的路由,并且它们起作用了:我可以毫无问题地从一个页面转到另一个页面。

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> .但是,我想访问包含表单的页面,因为它是 Laravel,所以我将我的 csrf 令牌作为<meta>放在布局的<head>中。

Nevertheless, I keep getting errors that are the result of a lack of csrf token.尽管如此,由于缺少 csrf 令牌,我不断收到错误消息。 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.当我查看源代码时,我可以看到 Laravel 实际上加载了默认的 404 页面,这显然不包含任何 csrf 令牌。

My question is the following: how should I tell Vue or Laravel that he should let the other handle the url?我的问题如下:我应该如何告诉 Vue 或 Laravel 他应该让另一个处理 url? Is there an other way than declare the same routes for Laravel than for VueJS?除了为 Laravel 声明与 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 .我们使用这个路由规则将所有请求指向 Vue 应用程序,在我们的例子中是example.com/app Adjust as necessary.根据需要进行调整。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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