Fai*_*lik 1 reactjs react-router
我是 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'));
Run Code Online (Sandbox Code Playgroud)
经过这么多工作后,当我像这样更改代码时它起作用了......
const history = createHashHistory();
const middleware = routerMiddleware(history);
const sagaMiddleware = createSagaMiddleware(); //saga
export const store = createStore(combineReducers({ login: reducer, router: routerReducer }),applyMiddleware(sagaMiddleware,middleware));
//no error
sagaMiddleware.run(watcherSaga);
ReactDOM.render((
<Provider store={store}>
<ConnectedRouter history={history}>
<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>
</ConnectedRouter>
</Provider>
), document.getElementById('root'));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4026 次 |
| 最近记录: |