我是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'));
答案 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'));