【问题标题】:Translating a 404.html file in a React app在 React 应用程序中翻译 404.html 文件
【发布时间】:2018-08-31 12:58:30
【问题描述】:

我有一个 React 应用程序,它有一个 index.html 文件和一个 bundle.js,其中包含应用程序的所有 javascript。 React 应用程序使用 React Intl 进行本地化。

如果出现 404 错误,我想显示 404 错误页面。我创建了一个静态 404.html 文件来显示错误消息。

由于我所有的本地化逻辑都在 bundle.js 内的 Index.html 中,我如何能够本地化我的静态 404.html 页面的文本?我需要为每种语言创建一个单独的 404.html 页面吗?

【问题讨论】:

    标签: html reactjs intl


    【解决方案1】:

    与其使用静态 html 作为 404 错误页面,不如使用组件

    <Route route="/" component={App}>
        <Route path=":area" component={Area}>
            <Route path=":city" component={City} />
            <Route path=":more-stuff" component={MoreStuff} />    
        </Route>
        <Route path="*" component={My404Component} />
    </Route>
    

    然后确保您的 My404Component 使用 React Intl 支持区域设置。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-04-03
      • 1970-01-01
      • 1970-01-01
      • 2017-02-11
      • 2017-10-09
      • 2011-04-07
      • 2021-12-19
      相关资源
      最近更新 更多