Ric*_*ton 25 html javascript css jquery firebase
我正在尝试组织我的项目以使其更易于维护.我有大量的html模板,我被迫将它们全部放在公共目录中.我真的很想像这样组织它
public directory
views
index.html
register.html
terms.html
privacy.html
support.html
stylesheets
styles.css
scripts
script.js
authentication.js
Run Code Online (Sandbox Code Playgroud)
但它看起来像这样
public
index.html
register.html
terms.html
privacy.html
support.html
script.js
authentication.js
styles.css
Run Code Online (Sandbox Code Playgroud)
这是我的firebase.json档案
{
"firebase": "funmathgame",
"public": "mathgame",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
]
}
Run Code Online (Sandbox Code Playgroud)
这是我收到的错误消息
网页未找到
该文件不存在,并且
index.html在当前目录或404.html根目录中找不到该文件.我为什么看到这个?
您可能已为应用程序部署了错误的目录.检查
firebase.json并确保公共目录指向包含index.html文件的目录.您还可以
404.html在站点的根目录中添加a ,以使用自定义错误页面替换此页面.
第一个结构更好,因为它分隔代码.每当我在文本编辑器中运行文件时,此结构都有效.但是,每当我部署到firebase时它都不起作用.
举个例子,这就是我引用样式表的方法
<head>
<title>Frequently Asked Questions</title>
<link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css'>
</link>
<link rel='stylesheet' href='../stylesheets/styles.css'></link>
Run Code Online (Sandbox Code Playgroud)
在上面的目录结构中,我在public/views目录中.我..用来将一个目录移回公共目录,然后转发到stylesheets目录.但是,这里我的index.html文件不在公共目录中,而是在public/views目录中.
我看过Firebase网站,但仍然找不到任何想法.
https://www.firebase.com/docs/hosting/guide/full-config.html
hee*_*nee 11
如果您愿意拥有/views/index.html应用程序的地址栏,则可以/通过向您的地址添加redirects元素来 进行重定向firebase.json.此外,您的public属性可能不正确.所以将firebase.json文件更改为:
{
"firebase": "funmathgame",
"public": "public",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"redirects": [
{
"source": "/",
"destination": "/views/index.html",
"type": 302
}
]
}
Run Code Online (Sandbox Code Playgroud)
这样,任何访问https://funmathgame.firebaseapp.com/的用户都将被重定向到https://funmathgame.firebaseapp.com/views/index.html,所有相关网址都将得到正确解析.
这肯定是一个难题.部署到Firebase时,Firebase正在index.html您的公共目录中查找文件.此公共目录也称为根目录.
我正在使用一个有角度的应用程序,而我只是在我的部分中使用了错误的路径.但这非常棘手.
我必须设置一个角度控制器,它注入$document依赖项以获取页面的标题.如果页面的标题与根页的标题匹配,我将使用ng-href该views目录前置到相对URL.
否则,如果您在views目录中,并搜索了更多视图,它将显示一个类似的路径views/views/page1.html.这就是为什么我们ng-href对这些有不同的条件.
这就是我导航的样子
<ul class='nav navbar-nav'>
<li><a ng-href="{{ page == home ? 'views/help.html' : 'help.html' }}">Help</a></li>
<li><a ng-href="{{ page == home ? 'views/achievements.html' : 'achievements.html' }}">Achievements</a></li>
<li><a ng-href="{{ page == home ? 'views/scores.html' : 'scores.html' }}">Scores</a></li>
<li><a ng-href="{{ page == home ? 'views/shop.html' : 'shop.html' }}">Shop</a></li>
<li><a ng-href="{{ page == home ? 'views/faq.html' : 'faq.html' }}">FAQs</a></li>
<li><a ng-href="{{ page == home ? 'views/related.html': 'related.html' }}">More Games</a></li>
</ul>
Run Code Online (Sandbox Code Playgroud)
最后,我的目录结构如下所示
public
assets
stylesheets
styles.css
views
partials
scripts.html
header.html
footer.html
page1.html
...
scripts
controllers
script1.js
...
index.html
Run Code Online (Sandbox Code Playgroud)
如果更改firebase.json文件,也可以将索引文件放在views目录中.
{
"firebase": "firebase-app",
"public": "root/views",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
]
}
Run Code Online (Sandbox Code Playgroud)
您只需更改firebase应用中的public关键字即可.花了很多时间,因为我忘了我必须有条件地改变路径.此外,要导航回上一个目录,您必须执行类似的操作../
| 归档时间: |
|
| 查看次数: |
4958 次 |
| 最近记录: |