如何从单页应用程序重写中排除路径(/图像)? [英] How do I exclude a path (/images) from single page app rewrite?

查看:61
本文介绍了如何从单页应用程序重写中排除路径(/图像)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆