【问题标题】:React-Router 4: Route all 404 paths except 'manifest.json' and 'sitemap.xml'React-Router 4:路由除 'manifest.json' 和 'sitemap.xml' 之外的所有 404 路径
【发布时间】:2018-05-12 19:30:19
【问题描述】:

我有如下定义的 react-router 配置

import React from 'react'
import { Switch, Route } from 'react-router-dom'
import Home from '../Home'
import AboutUs from '../containers/AboutUs'

const Router = () => (
  <main>
    <Switch>
      <Route exact path='/' component={Home}/>
      <Route exact path='/aboutUs' component={AboutUs}/>
      <Route path='*' exact component={Home} />
    </Switch>
  </main>
)

export default Router

我正在尝试将 404 路由路由回主页。这工作正常,但添加此&lt;Route path='*' exact component={Home} /&gt; 路由后,我无法访问

  1. www.mywebsite.com/sitemap.xml
  2. www.mywebsite.com/manifest.json

它们也被路由到主页。所以基本上我想要实现的是将所有Not Found 路由路由到主页,xml or json 文件除外

【问题讨论】:

    标签: reactjs react-router react-router-v4


    【解决方案1】:

    我从* 路径中删除了exact,它起作用了

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-05
      • 2017-09-08
      • 2020-12-11
      • 2014-07-31
      • 1970-01-01
      • 2017-08-11
      相关资源
      最近更新 更多