【问题标题】:redirect route with # laravel使用 # laravel 重定向路由
【发布时间】:2022-01-26 22:09:51
【问题描述】:

我使用“return redirect()->route()”进行路由,但我有一个名为“#tab4”的选项卡,但无法使用 redirect()->route 将其添加到 url。我想在提交后显示相同的选项卡,但无法设置 url。当我使用 redirect()->back() 时,看不到成功消息并且页面不会重新刷新。如何在 laravel 中做到这一点?

sessionsuccess("asdfghj.");

return  redirect()->route('manage.customers.detail', ['account' => $this->account->id]);

我想要的网址:http://localhost:8000/manage/customers/detail/9#tab4

【问题讨论】:

标签: php laravel


【解决方案1】:

路由上的web.php

Route::view('/#detail', 'manage.customers.detail/{account_id}')->name('detail');

在控制器上

return  redirect()->route("detail")->with("account_id"=>$this->account_id);

试试这个。我相信这样做

【讨论】:

  • 所以你会为每个标签创建不同的路由?这可能行得通,但这不是一个好的解决方案。
  • 你可以使用前缀为这个foreach,但不需要这个manage.customers.detail只是改变参数值路由是一样的,但如果你想使用前缀路由补丁foreach
  • 或者你可以保持简单和动态,并将选项卡链接到输出的路由。因此,您无需为每个新选项卡编辑路由文件。在路由中添加选项卡链接根本不是一个好的解决方案。你的路由文件会大很多,更难维护。
  • 我对这个主题一无所知。你能分享一个例子吗?
【解决方案2】:

尝试使用:

return redirect()->to(route('manage.customers.detail', ['account' => $this->account->id]).'#tab4');

【讨论】:

  • 请解释你的答案,而不是仅仅说“试试这个”。
【解决方案3】:

将当前选项卡存储在会话变量中。加载视图后,可以使用会话并检索您的最后一个标签

【讨论】:

    【解决方案4】:

    您需要将您的标签保存为 Flash,以便您提交时该标签可以处于活动状态 在你的控制器方法中

    Session::flash('tab', 'table_name');
    

    在你看来,你可以这样工作

    Session::has('tab')? 'active' :''
    

    了解更多详情 https://laravel.com/docs/5.0/session#flash-data

    第二种工作方式链接

    return redirect()->route('manage.customers.detail', ['account' => $this->account->id, '#tab4']);

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-20
      • 2020-03-24
      • 2018-07-07
      • 2017-06-19
      • 2021-04-26
      • 1970-01-01
      • 1970-01-01
      • 2017-04-17
      相关资源
      最近更新 更多