这是问题的后续:
onEnter not called in React-Router
以下代码正确执行重定向,但实际上并未呈现与重定向 url 相关的组件。
下面是我的代码,对上一个问题中给出的代码做了一个小的改编。
// Authentication "before" filter
function requireAuth(){
if(isLoggedIn())
return <Home />
else
return <Redirect to="/front"/>
}
// Render the app
render(
<Provider store={store}>
<Router history={history}>
<App>
<Switch>
<Route path="/front" component={Front} />
<Route path="/home" render={requireAuth} />
<Route exact path="/" render={requireAuth} />
<Route path="*" component={NoMatch} />
</Switch>
</App>
</Router>
</Provider>,
document.getElementById("lf-app")
)
重定向后刷新浏览器时,页面正确显示。
我希望渲染能够工作,但它没有......这是错误还是期望的行为?
历史:
...
import {createBrowserHistory} from "history";
// Init sagaMiddleware
const sagaMiddleware = createSagaMiddleware();
const store = createStore(
appReducers,
applyMiddleware(sagaMiddleware)
);
const history = syncHistoryWithStore(createBrowserHistory(), store);