本文介绍了Laravel样式表和javascript不会为非基本路线加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的-我知道这是一个非常基本的问题,但我无法弄清楚. 这是一个关于Laravel的问题.

Okay--I know this is a really elementary issue, but I can't figure it out. This is a question regarding Laravel.

基本上,我的样式表已嵌入默认布局视图中.我目前仅使用常规的CSS来链接它们,例如:

Basically, I have my stylesheets embedded in my default layout view. I'm currently just using regular css to link them, such as:

<link rel="stylesheet" href="css/app.css" />

当我在诸如/about 之类的单层路线上时,效果很好,但是当我更深入如/about/me 之类的路线时,它将停止工作.

It works great when I am at a single level route such as /about, but stops working when I go deeper, such as /about/me.

如果我查看Chrome的开发者控制台,会看到以下一些错误(仅适用于更深层的路由):

If I look at Chrome's developer console I see some of the following errors (only for the deeper routes):

Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://example.dev/about/css/app.css".

因此,很明显,它现在正在"about"文件夹中寻找css,这当然不是一个文件夹.

So clearly it is now looking for the css inside the "about" folder--which of course isn't a folder at all.

我只希望它在同一位置查找资产,而不管路线如何.

I just want it to look in the same place for the assets regardless of the route.

推荐答案

对于Laravel 4& 5:

For Laravel 4 & 5:

<link rel="stylesheet" href="{{ URL::asset('assets/css/bootstrap.min.css') }}">

URL::asset 会链接到您的 project/public/ 文件夹,因此请在其中保存脚本.


URL::asset will link to your project/public/ folder, so chuck your scripts in there.


这篇关于Laravel样式表和javascript不会为非基本路线加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 12:44