【问题标题】:What caused this warning in react-router?是什么导致 react-router 中出现此警告?
【发布时间】:2016-08-02 22:28:04
【问题描述】:

browser.js:警告:[react-router] History mixin 是 已弃用,请自行访问context.router contextTypes.

我的路线文件

const routes = (
  <Provider store={store}>
      <Router history={browserHistory}>
        <Route path="/" component={RootComponent}>
          <IndexRoute component={HomePage} />

          <Route path="profile" component={ProfilePage} >
            <IndexRoute component={ProfilePage} />
            <Route path="view/:profileId" component={ProfilePage} />
            <Route path="add" component={AddProfile} />
            <Route path="edit/:profileId" component={EditProfile} />
          </Route>

          <Route path="login" component={Login} />
          <Route path="onboard" component={Onboard} />
        </Route>
      </Router>
  </Provider>
);

export default routes;

还有根

import React from 'react';
import { render } from 'react-dom';
import routes from './routes';
import "babel-polyfill";

const mountPoint = document.getElementById('application-root');

if (mountPoint) {
  render(routes, mountPoint);
} else {
  console.error('could not find application mount point');
}

反应路由器 v2.6.1

【问题讨论】:

  • 在发出该警告的行上放置一个断点,并检查堆栈跟踪,直到检查此内容的位置。然后你就知道到底是什么原因造成的了。

标签: reactjs react-router react-routing


【解决方案1】:

错误可能是由这一行引起的。您从哪里导入“browserHistory”?

<Router history={browserHistory}>

在最新版本的react-router中,需要从react-router包本身导入history

import { browserHistory } from 'react-router'

<Router history={browserHistory} routes={routes} />

更多详情请参考this link

【讨论】:

    猜你喜欢
    • 2019-08-28
    • 2018-09-08
    • 1970-01-01
    • 1970-01-01
    • 2015-02-28
    • 1970-01-01
    • 1970-01-01
    • 2019-06-15
    • 1970-01-01
    相关资源
    最近更新 更多