简体   繁体   English

如何使用 if 路由条件在 2 个单独的视图函数中使用相同的渲染? (Laravel/Livewire)

[英]How do I use the same render in 2 separate view functions using the if route is condition? (Laravel/Livewire)

How do I use the same render in 2 separate view functions using the if route is condition?如何使用 if 路由条件在 2 个单独的视图函数中使用相同的渲染? (Laravel/Livewire)?? (Laravel/Livewire)??

I want to render 2 different Livewire.view in the render function by checking the route is same to current route, something like that:我想通过检查路线与当前路线相同,在渲染 function 中渲染 2 个不同的 Livewire.view,如下所示:

public function render()
{
   if (\Route::named('admin-appointments')) {
      return view('livewire.admin-appointments', [
      'data' => $this->read(),
      ]);
   }
   else{
      return view('livewire.user-appointments', [
      'data' => $this->read(),
      ]);
   }
}

but I have alwayse problem!!但我总是有问题!

Making the render depending on the route is unlikely to work.根据路线进行渲染不太可能奏效。 The first request will have the correct route, but all following requests will be triggered by Livewire and not match your route anymore.第一个请求将具有正确的路由,但所有后续请求将由 Livewire 触发,不再与您的路由匹配。 Instead, you need set a flag while mounting the Livewire component and make your rendering depending on this.相反,您需要在安装 Livewire 组件时设置一个标志,并根据此进行渲染。

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

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