我正在用react + react-router 构建一个React App,但是我对重定向有问题。
我有下一个文件夹结构:
...
/public
/index.html (react index)
/tos/
/terms.html
/privacy.html
...
/src
index.js
App.js
...
和index.js:
class App extends Component {
render() {
return (
<Router>
<Switch>
<Route exact path="/" component={Home}/>
<Route path="/settings" component={Settings}/>
</Switch>
</Router>
)
}
}
ReactDOM.render(<App/>, document.getElementById('root'));
registerServiceWorker();
Run Code Online (Sandbox Code Playgroud)
问题是当我想重定向到/public/tos/terms.html或时/public/tos/privacy.html(有时(在chrome中更频繁)),我不能。该项目再次呈现索引,并显示空白页,因为该路由/public/tos/terms.html或未/public/tos/privacy.html在“路由开关”中声明。
另一方面,我在相同的base_url中有另一个“没有反应”的项目,但是在其他端口监听,www.my-project.com:4040/other并且在下一个路由中配置了它www.my-project.com/other。但是在这种情况下,我遇到了同样的问题,当我从我的React-app重定向到此路由时,react不要重定向并再次呈现其中的no App.js组件。
有人可以告诉我重定向到同一项目中其他位置的任何方法,但出于反应?