反应window.onload上的浏览器兼容性问题?

时间:2018-04-30 07:05:14

标签: javascript reactjs routing routes reactjs-flux

成功进行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中正确重定向到特定路由。

我已经工作了一个星期,仍然找不到任何污垢。修正的问题对我非常有帮助。

0 个答案:

没有答案