【发布时间】:2018-09-04 08:21:26
【问题描述】:
我是 React js 的新手,我正在为我的项目使用哈希路由,我有一个登录页面和仪表板。当我单击登录按钮时,我应该重定向到仪表板。
目前,当我单击登录按钮时,网址正在从“http://localhost:8080/#/login”更改为http://localhost:8080/#/dashboard - 但页面未呈现.. :(
这是我用来推送的代码 - store.dispatch(push('#/dashboard'));
使用此链接进行配置 - https://github.com/ReactTraining/react-router/tree/master/packages/react-router-redux
const history = createHistory();
const middleware = routerMiddleware(history);
const sagaMiddleware = createSagaMiddleware(); //saga
export const store = createStore(combineReducers({ login: L_reducer, router: routerReducer }),applyMiddleware(sagaMiddleware,middleware));
//no error
sagaMiddleware.run(watcherSaga);
ReactDOM.render((
<Provider store={store}>
<ConnectedRouter history={history}>
<HashRouter>
<Switch>
<Route exact path="/login" name="Login Page" component={Login}/>
<Route exact path="/register" name="Register Page" component={Register}/>
<Route path="/" name="Home" component={Full}/>
</Switch>
</HashRouter>
</ConnectedRouter>
</Provider>
), document.getElementById('root'));
【问题讨论】:
-
好吧,你没有匹配
/dashboard的路由,所以没有任何渲染是正常的。
标签: reactjs react-router