成功进行API调用后,我调用window.onload
组件刷新以重定向到特定路由。
export function _getUserPlanForUser(data) {
let token = localStorage.getItem('accessToken');
let url = "/userplans/listuserplans?access_token=" + token;
let BASE = "http://172.104.176.144:9080"
let actualurl = BASE + url;
Api._callAPI(actualurl, 'GET', data, (type, dt) => {
if (type == 'success') {
dispatcher.dispatch({
type: 'UsersPlansForUser',
data: dt,
})
window.onload = function() {
if(!window.location.hash) {
window.location = window.location + '#loaded';
window.location.reload(true);
}
}
}
});
}
在routes.js
文件中,我根据条件验证
import React from 'react';
import { Route, IndexRoute } from 'react-router';
import App from './components/App';
import loginPage from './components/login/login.component.jsx';
import dashboard from './components/dashboard';
import Home from './components/Home/home.jsx';
import Myplan from './components/MyPlan/myplan.jsx';
export default (
<Route component={App}>
<Route path="/" >
<IndexRoute component={loginPage} />
</Route>
<Route path="/dashboard" component={dashboard} >
{
(localStorage.getItem("ValidateRoute")) == "0" ?
[
<IndexRoute component={Myplan} />,
<Route path='/home' component={Home} />
] : [
<IndexRoute component={Home} />,
<Route path='/myplan' component={Myplan} />
]
}
</Route>
</Route>
);
基于条件ValidateRoute
我在成功重新加载后路由到特定组件!
Chrome上的所有内容都运行良好,但由于window.reload
无效,因此不会重定向到特定路由!
请给我一些指导,以便重新加载Mozilla(或)在Mozilla中正确重定向到特定路由。
我已经工作了一个星期,仍然找不到任何污垢。修正的问题对我非常有帮助。