我有一个代码:
import React from 'react'; import ReactDOM from 'react-dom'; import Navigation from './Navigation'; import PublicPage from './PublicPage'; import LoginPage from './LoginPage'; import SecuredPage from './SecuredPage'; import {Route, Switch, Redirect, BrowserRouter} from 'react-router-dom'; ReactDOM.render( <BrowserRouter> <Navigation> <Switch> <Redirect from='/' to='/public'/> <Route path="/public" component={PublicPage}/> <Route path="/login" component={LoginPage}/> <Route path="/secured" component={SecuredPage}/> </Switch> </Navigation> </BrowserRouter>, document.getElementById("react-app") );
现在,我想将路径/重定向到/public路径,但是以某种方式该配置不起作用。其他路线也会停止渲染。我想我做的一切都像在文档中
/
/public
交换
<Redirect from='/' to='/public'/>
与
<Redirect exact from='/' to='/public'/>
因为否则“ /”将匹配所有内容,从而创建无限重定向循环