Laravel 5未加载非基本路由的样式表和脚本

Laravel 5未加载非基本路由的样式表和脚本,laravel,model-view-controller,laravel-5,Laravel,Model View Controller,Laravel 5,在我的Laravel 5应用程序中,链接非基本路线的样式表、脚本和图像时遇到问题。当我访问example.com/about时,脚本和样式表工作正常,但如果我访问example.com/about/something,脚本和样式表将链接到example.com/about/css/style.css,而不是example.com/css/style.css 我的代码如下: Routes.php: Route::get('about/{slug?}', ['as' => 'officerP

在我的Laravel 5应用程序中,链接非基本路线的样式表、脚本和图像时遇到问题。当我访问example.com/about时,脚本和样式表工作正常,但如果我访问example.com/about/something,脚本和样式表将链接到example.com/about/css/style.css,而不是example.com/css/style.css

我的代码如下:

Routes.php:

 Route::get('about/{slug?}', ['as' => 'officerProfile', 'uses' => 'PagesController@about']);
PagesController.php:

public function about($slug = 'president')
{
    $officers = Officer::all();
    $currentOfficer = Officer::where('slug', $slug)->first();
    return view("pages.about", ['title' => $this->makeTitle('Learn About Us')])->with('officers', $officers)->with('currentOfficer', $currentOfficer);
}
layout.blade.php:

{!! HTML::script('https://code.jquery.com/jquery-2.1.4.min.js') !!}
{!! HTML::script('js/skel.min.js') !!}
{!! HTML::script('js/skel-layers.min.js') !!}
{!! HTML::script('js/init.js') !!}
{!! HTML::script('js/scripts.js') !!}
<noscript>
    {!! HTML::style('css/skel.css') !!}
    {!! HTML::style('css/style.css') !!}
    {!! HTML::style('css/style-desktop.css') !!}
</noscript>
{!!HTML::script('https://code.jquery.com/jquery-2.1.4.min.js') !!}
{!!HTML::script('js/skel.min.js')
{!!HTML::script('js/skel layers.min.js')!!}
{!!HTML::script('js/init.js')
{!!HTML::script('js/scripts.js')
{!!HTML::style('css/skel.css')
{!!HTML::style('css/style.css')
{!!HTML::style('css/style desktop.css')

出于某种原因,当加载的路由为example.com/about/something时,Laravel认为基本URL为example.com/about。我也试过了,但它仍然路由到example.com/about/images/image.jpg,而不是example.com/images/image.jpg。如有任何建议,将不胜感激。谢谢大家!

您使用的是相对路径,需要绝对路径。请参见下面的示例,我添加的唯一内容是带前缀的
/

{!! HTML::script('https://code.jquery.com/jquery-2.1.4.min.js') !!}
{!! HTML::script('/js/skel.min.js') !!}
{!! HTML::script('/js/skel-layers.min.js') !!}
{!! HTML::script('/js/init.js') !!}
{!! HTML::script('/js/scripts.js') !!}
<noscript>
    {!! HTML::style('/css/skel.css') !!}
    {!! HTML::style('/css/style.css') !!}
    {!! HTML::style('/css/style-desktop.css') !!}
</noscript>
{!!HTML::script('https://code.jquery.com/jquery-2.1.4.min.js') !!}
{!!HTML::script('/js/skel.min.js')
{!!HTML::script('/js/skellayers.min.js')
{!!HTML::script('/js/init.js')
{!!HTML::script('/js/scripts.js')
{!!HTML::style('/css/skel.css')
{!!HTML::style('/css/style.css')
{!!HTML::style('/css/style desktop.css')
相对路径加载与当前路径相关的文件。例如从页面
http://example.com/about/us
您可以相对加载
图像/logo.png
,这将导致实际请求
http://example.com/about/images/logo.png


绝对路径始终来自主机名:与上面的示例相同,但您将加载
/images/logo.png
,这将导致
http://example.com/images/logo.png

谢谢!调试时肯定错过了。