我在我的布局中使用了预加载器gif,它放在public / img中,并通过以下代码行使用:< img src =“img / preloader.gif”alt =“Preloader”>
这非常好……
你的图像src正在使用一个名为a的东西 的 相对URI 强> ,基本上说“获取当前的URI,并将其添加到它的末尾”。
当你在主页上时 example.com ,你的形象路径是 example.com/img/preloader.gif , 哪个是对的。
example.com
example.com/img/preloader.gif
一旦您使用多个细分受众群的更深层次的URI,例如 example.com/test/foobar ,图像URI变为 example.com/test/img/preloader.gif 这显然是不正确的。
example.com/test/foobar
example.com/test/img/preloader.gif
在Laravel中解决这个问题的最简单和最推荐的方法是使用 asset() 要么 secure_asset() 助手 。这将有助于为图像/资产生成绝对URI,并且无论用户所在的应用页面是哪个页面都是正确的。
asset()
secure_asset()
<img src="{!! asset('img/preloader.gif') !!}" alt="Preloader">