散列路由导航无法正常工作 - 对路由器redux进行反应

时间:2018-03-26 08:39:23

标签: reactjs react-router

我是React js的新手,我正在为我的项目使用哈希路由,我有一个登录页面和仪表板..当我点击登录按钮时,我应该重定向到仪表板。

目前,当我点击登录按钮时,网址会从' http://www.mynotebucket.com/update-mysql-under-xmpp/'至http://localhost:8080/#/login - 但页面未呈现.. :(

这是我用来推送的代码 -     store.dispatch(推('#/仪表板'));

使用此链接配置 - http://localhost:8080/#/dashboard

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'));

1 个答案:

答案 0 :(得分:1)

当我改变了这样的代码后,经过如此多的工作......

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'));