React路由器更改URL但不更改视图(仅在Internet Explorer 11上)

时间:2017-07-11 12:42:23

标签: reactjs internet-explorer react-router react-redux mern

基本上一切都在Chrome和Firefox中正常运行,但是在点击链接元素后,IE上的URL正在变化,而不是视图。我在react-router中了解Update Blocking问题,但我认为事实并非如此 - 因为我很遗憾,它只在IE上失败了。

这是我的堆栈(MERN Starter):

"react": "^15.1.0",
"react-bootstrap": "^0.31.0",
"react-dom": "^15.1.0",
"react-helmet": "^3.1.0",
"react-intl": "^2.1.2",
"react-redux": "^4.4.5",
"react-router": "2.8.0",
"redux": "^3.5.2",
"redux-thunk": "^2.1.0",

App.js< - 根元素(/client/App.js)

export default function App(props) {
  return (
    <Provider store={props.store}>
      <IntlWrapper>
        <Router history={browserHistory}>
          {routes}
        </Router>
      </IntlWrapper>
    </Provider>
  );
}

Routes.js

<Route path="/" component={App}> // <- it's pointing to app.js pasted below
    <IndexRoute
      getComponent={(nextState, cb) => {
        require.ensure([], require => {
          cb(null, require('./modules/Main/pages/Main/Main').default);
        });
      }}
    />
    <Route
      path="posts"
      getComponent={(nextState, cb) => {
        require.ensure([], require => {
          cb(null, require('./modules/Post/pages/PostListPage/PostListPage').default);
        });
      }}
    />
    <Route
      path="posts/:slug-:cuid"
      getComponent={(nextState, cb) => {
        require.ensure([], require => {
          cb(null, require('./modules/Post/pages/PostDetailPage/PostDetailPage').default);
        });
      }}
    />
    <Route
      path="screenBuilder"
      getComponent={(nextState, cb) => {
        require.ensure([], require => {
          cb(null, require('./modules/ScreenBuilder/pages/ScreenBuilderPage/ScreenBuilderPage').default);
        });
      }}
    />
  </Route>

再次App.js(client / modules / App / app.js),但这次是路由指向的模块的“contener”元素:

export class App extends Component {
  constructor(props) {
    super(props);
    this.state = { isMounted: false };
  }

  componentDidMount() {
    this.setState({isMounted: true}); // eslint-disable-line
  }

  toggleAddPostSection = () => {
    this.props.dispatch(toggleAddPost());
  };

  render() {
    return (
      <div>
        {this.state.isMounted && !window.devToolsExtension && process.env.NODE_ENV === 'development' && <DevTools />}
        <div>
          // <Helmet/>
          <Header
            switchLanguage={lang => 
            this.props.dispatch(switchLanguage(lang))}
            intl={this.props.intl}
            toggleAddPost={this.toggleAddPostSection}
          />
          <div className={styles.container}>
            {this.props.children}
          </div>
          <Footer />
        </div>
      </div>
    );
  }
}

export default withRouter(connect(mapStateToProps)(App));

Link元素的示例:

<Link to="/posts" >Posts List</Link>

我从昨天开始就坚持这一点,而目前我还不知道如何解决这个问题。在IE控制台中没有反馈,也没有请求出来......点击链接除了更改URL之外什么都不做。

任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:2)

包括babel-polyfill

对于Webpack ,请将其添加到entry配置:

module.exports = {
  entry: ["babel-polyfill", "./app/js"]
};

您也可以将其导入到其他文件的顶部:import "babel-polyfill",但要确保首先将其包含在内。