如何将 manifest.json 的 start_url 设置为站点的根目录? [英] How do I set the start_url of a manifest.json to be the root of the site?
问题描述
我有一个 manifest.json
并且它有一个 start_url
属性,我想指向我的单页应用程序的第一个文件.
I have a manifest.json
and it has a start_url
property that I want to point to the first file of my single page application.
这是index.html
,它是站点的根目录.我希望这是 start_url
,但从不要求该文件作为 URL.
This is index.html
, and it's the root of the site. I want this to be the start_url
, but that file is never asked for as a URL.
如何将 start_url
指向网站的相对根目录?
How do I point start_url
at the relative root of the site?
例如,假设站点位于 https://example.com
,start_url
的值应该在 https://example 中.com/manifest.json
?我希望 PWA 从 https://example.com
和 not https://example.com/index.html
开始.PWA 可能放在不同的域中,因此 start_url
需要是相对的,而不是绝对的.
For instance, suppose the site is at https://example.com
, what should the value of start_url
be in https://example.com/manifest.json
? I want the PWA to start at https://example.com
and not https://example.com/index.html
. The PWA might be put on a different domain, so start_url
needs to be relative, not absolute.
推荐答案
如果您在站点的根目录中运行,例如 https://example.com/manifest.json
或 <代码>https://test.example.com/manifest.json 你可以使用"start_url": "/"
.
If you are running in the root of a site, for instance https://example.com/manifest.json
or https://test.example.com/manifest.json
you can use "start_url": "/"
.
但是,这也会将 https://example.com/test/manifest.json
映射到 https://example.com/
,因为它是在清单范围之外的文件夹中.
However, this will also map https://example.com/test/manifest.json
to https://example.com/
, which fails because it's in a folder outside the scope of the manifest.
相反,如果您使用的是子目录,则需要同时设置 scope
和 start_url
:
Instead, if you are using a sub-directory you need to set both a scope
and the start_url
:
"start_url": "./"
"scope": "."
这将导致 https://example.com/test/manifest.json
按预期映射到 https://example.com/test/
.
This will cause https://example.com/test/manifest.json
to map to https://example.com/test/
as expected.
这篇关于如何将 manifest.json 的 start_url 设置为站点的根目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!