Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

升级后旧的语法不支持了 #1205

Closed
102010cncger opened this issue Sep 10, 2017 · 2 comments
Closed

升级后旧的语法不支持了 #1205

102010cncger opened this issue Sep 10, 2017 · 2 comments

Comments

@102010cncger
Copy link

102010cncger commented Sep 10, 2017

Code to reproduce the issue: (请提供可复现的代码或者步骤)

const Routers = function ({history, app}) {
  const routes = [
    {
      path: '/',
      component: App,
      indexRoute: {
        component: Welcome,
      },
      childRoutes: [
        {
          path: 'index',
          childRoutes: [
            {
              path: 'option1',
              name: 'option1',
              tableName: 'test',
              getComponent: DBTableContainer,
            }, {
              path: 'programme',
              name: 'programme',
              component: ProgrammeIndex,
            }, {
              path: 'project',
              name: 'project',
              tableName: 'project',
              getComponent: DBTableContainer,
            },
            {
              path: 'option2',
              component: Error,
            },
          ],
        }, {
          path: '*',
          component: Error,
        },
      ],
    },
  ];
  return <Router history={history} routes={routes}/>;
};

Routers.propTypes = {
  history: PropTypes.object,
  app: PropTypes.object,
};

export default Routers;

Expected behavior: (预期的正常效果)

以上写法以前可以

Actual behavior: (实际效果)

现在这写法不支持了,用新的写法,非redux组件中的this.props变成了其他内容,不是react的内容,非常支持新版本的更新,但this.props变成了其他内容是咋回事?

出问题地方如下

class App extends React.Component {
componentWillMount() {
    console.log(this.props);
  }
...............
}
````````
新路由写法为 这里贴的代码有问题....
``````
import React from 'react';
import PropTypes from 'prop-types';
import {Switch, Route, Redirect, routerRedux} from 'dva/router';
import dynamic from 'dva/dynamic';
import App from './components/App';
import Welcome from './components/Welcome';
import Error from './components/Error';

const {ConnectedRouter} = routerRedux;

const Routers = function ({history, app}) {
  return (
    <ConnectedRouter history={history}>
      <App>
        <Switch>
          <Route exact path="/" render={() => (<Redirect to="/welcome"/>)}/>
          <Route
            key="welcome"
            exact
            path="/welcome"
            component={Welcome}
          />
          <Route component={Error}/>
        </Switch>
      </App>
    </ConnectedRouter>
  );
};

Routers.propTypes = {
  history: PropTypes.object,
  app: PropTypes.object,
};

export default Routers;

Versions of packages used: (哪个库的哪个版本出现的问题)

1.2.1-->2.0.1后出现

@longzhaobi
Copy link

longzhaobi commented Sep 10, 2017

你直接升级dva,这个肯定是不支持的,因为dva使用的路由版本是4,已经不兼容3这种写法了,你如果要兼容,去看作者发的issue,我就是按照里面这个升级的,把dva换成dva-react-router-3。issue地址:sorrycc/blog#48

@sorrycc sorrycc closed this as completed Sep 10, 2017
@13296634573
Copy link

@longzhaobi 请问直接npm install dva-react-router-3 --save 然后把import { browserHistory } from 'dva/router' 改成 import { browserHistory } from 'dva-react-router-3/router' 就可以了吗?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants