1

这是我的代码:

class noMatch extends React.Component {
  render() {
    return 'Not Found'
  }
}
ReactDOM.render(
   <BrowserRouter>
      <Switch>
        <Route exact path='/(index.html)?' component={App}/>
        <Route component={noMatch}/>
      </Switch>
    </BrowserRouter>,
  mountNode
);

该应用程序按预期在 localhost:3000/ 和 localhost:3000/index.html 中运行。但是当没有匹配时,我的 no Match 不会渲染?我正在关注此处文档中的 noMatch 教程。帮助?

4

1 回答 1

0

你的路由器代码看起来找到了。如果你只是在你的 noMatch 组件中返回字符串,你应该返回有效的 React 元素,例如:

class noMatch extends React.Component {
    render() {
        return (
            <div>Not Found</div>
        );
    }
}
于 2017-06-30T07:21:02.933 回答