如何从单页应用程序重写中排除路径(/图像)? [英] How do I exclude a path (/images) from single page app rewrite?
问题描述
我有一个React应用,并且在Firebase托管中具有通常的重写规则:
I have a react app and have the usual rewrite rule in firebase hosting:
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
我还有一个单独的/images目录,其中包含我不想重写的图像.
I also have a separate /images directory with images I don't want to be rewritten.
如何从重写中排除/images目录?
How do I exclude the /images directory from the rewrite?
推荐答案
我有点晚了,但在寻找类似问题时发现了这个问题.
I'm a bit late but I found this question while searching for a similar problem.
使用此重写规则:
"rewrites": [
{
"source": "!/images/**",
"destination": "/index.html"
}
]
关键是源"(与firebase.json中的许多字段一样)使用全局模式匹配表示法. 此规则不会重定向index.html上的所有内容("**"也一样),而是重定向图像文件夹和子文件夹中的所有不内容.
The key is that "source" (as a lot of fields in firebase.json) use a glob pattern matching notation. Instead of redirecting everything on index.html (as do " ** "), this rule redirect everything that is not in the images folder and subfolders.
这篇关于如何从单页应用程序重写中排除路径(/图像)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!