You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用查询字符串时,Livewire组件在浏览器前进后退时不渲染

问题:Livewire全页组件点击后退按钮无法正常渲染

我制作了一个带有查询字符串的简单全页Livewire组件,点击修改属性的按钮时组件可正常变更,但在谷歌浏览器中点击后退按钮时组件无法正常渲染。

Livewire组件类

class LivewireTest extends Component
{
    public $activeMenu = '';

    protected $queryString = [
        'activeMenu' => ['except' => '', 'as' => 'type'],
    ];

    public function render()
    {
        return view('testbaru::livewire-test')->layout('testbaru::livewire-layout');
    }

    public function ChangeMenu($menu)
    {
        $this->activeMenu = $menu;
    }
}

组件视图(livewire-test.blade.php)

<div>
    <div wire:key="{{ $this->activeMenu }}">
        <div wire:loading>
            Loading ...
        </div>
        <br>
        <button type="button" wire:click="ChangeMenu('home')">Menu</button>
        <button type="button" wire:click="ChangeMenu('profile')">Profile</button>
        <br>
        @if ($activeMenu == "home")
            Home Active
        @else
            Profile Active
        @endif
    </div>
</div>

布局视图(livewire-layout.blade.php)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    @livewireStyles
</head>
<body>
    <div>
        Welcome!
        <br>
        <br>
        {{ $slot }}
    </div>

    @livewireScripts
</body>
</html>

请问是我的操作有误,还是这是一个Bug?

谢谢

内容的提问来源于stack exchange,提问作者Kurowaffle

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.26 09:27:26