使用Firebase托管实施本地化的404页面 [英] Implementing localized 404 page with Firebase hosting

查看:68
本文介绍了使用Firebase托管实施本地化的404页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我的Web应用程序有两个区域设置:英语(myapp.com/en/)和法语(myapp.com/fr/).我想本地化404页面,以便对myapp.com/en/non-existentmyapp.com/non-existent的请求将返回英语版本的404页面,而对myapp.comm/fr/non-existent的请求将返回法语页面.

Say my web app has two locales: English(myapp.com/en/) and French(myapp.com/fr/). I want to localize my 404 pages, so that request to myapp.com/en/non-existent or myapp.com/non-existent would return an English version of the 404 page and request to myapp.comm/fr/non-existent would return a French one.

但是,似乎Firebase Hosting默认不提供此类功能,因为它仅允许一个404页(

However, it seems like Firebase Hosting does not provide such functionality by default, as it only allows a single 404 page(source)

那么,有没有一种方法可以使用Firebase Hosting来实现本地化的404页面?

So, is there a way of implementing a localized 404 page with Firebase Hosting?

推荐答案

从2020年8月12日开始,Firebase Hosting现在包括对 i18n内部化.

As of August 12th 2020, Firebase Hosting now includes support for i18n internalization.

这里是使用方法:

  1. 创建一个新目录,以将这些本地化文件(例如localized)托管在您的public目录下.
  2. 更新您的firebase.json文件以包括对该新目录的引用:
  1. Create a new directory to host these localized files (e.g localized) under your public directory.
  2. Update your firebase.json file to include a reference to this new directory:

// firebase.json

"hosting": {

  "public": "public",

  "ignore": [
     // ...
  ],

  "i18n": {
    "root": "/localized"  // directory that contains your "i18n content"
  }

  // ...
}

  1. localized目录下,创建一个名为fr的新目录,您可以在其中添加法语404.html文件.
  2. 运行firebase deploy来部署您的网站,现在您的法语用户应该被重定向到正确的页面:)
  1. Under the localized directory, create a new directory named fr, and that's where you can add your french 404.html file.
  2. Run firebase deploy to deploy your site and now your french users should be redirected to the correct page :)

请参见 Firebase文档有关国家和语言代码的更多信息.

See the Firebase Docs for more information on country and language codes.

这篇关于使用Firebase托管实施本地化的404页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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