我正在将 HTML 模板导入到我的 Laravel 应用程序中。我将所有 css/js 文件复制到 public 目录中各自文件夹中。我没有改变样式链接
<link rel="stylesheet" href="css/style.css"/>
到
<link rel="stylesheet" href="{{ URL::asset('css/animate.css') }}"/>
因为它工作得很好。但是,对于带有参数的 show 函数,在我的 ShopController 中,没有应用 css。如果我删除了 show 函数和路由中的参数“$id”,它又可以正常工作了。我不明白为什么 css 应用于所有没有传递数据的路由,但对于传递数据的路由失败。这是我的产品页面路线
Route::get('/shop/{product}', 'ShopController@show')->name('shop.show');
商店控制器:
public function show($id)
{
return view('product');
}
视图文件
<head>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
因为如果路由中有东西,那么它会尝试像这样获取它:http://localhost/routedata/css/style.css
你必须这样做
<link rel="stylesheet" href="{{ asset('css/style.css') }}"/>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句