Giter Site home page Giter Site logo

dva-knowledgemap's Issues

dva/router不返回children和routes

使用dva 2.0.1,router配置如下

import React from 'react';
import { Router, Switch, Route, IndexRoute } from 'dva/router';
import IndexPage from './routes/IndexPage'
import CountPage from './routes/CountPage'

function RouterConfig({ history }) {
  return (
    <Router history={history}>
      <Route path="/" component={IndexPage}>
        {/*<Switch>*/}
          <Route path="/count" component={CountPage}/>
          <Route path="/statements" component={CountPage}/>
        {/*</Switch>*/}
      </Route>
    </Router>
  );
}

export default RouterConfig;

在IndexPage中输出的props里面没有children和routes

import React from 'react';
import { connect } from 'dva';
import styles from './IndexPage.css';
import { Layout } from 'antd'
import Header from '../components/Header'

const { Sider, Content, Footer } = Layout;

const IndexPage = (props) => {
  const { children, routes } = props;
  console.log(props);
  return (
    <Layout>
      <Header routes={routes}>header</Header>
      <Layout>
        <Sider>sider</Sider>
        <Content>{children || "No content"}</Content>
      </Layout>
      <Footer>2017</Footer>
    </Layout>
  );
}

default

subscriptions中dispatch引发redux-soga浏览器抛异常:uncaught at sagaWithCatch

@sorrycc 我在subscriptions中dispatch引发redux-soga浏览器抛异常:uncaught at sagaWithCatch

下面是demo中的代码:

  namespace : 'user',
  state : {
    currentUser : {}
  },
  subscriptions : {
    setup({ dispatch, history }) {
      history.listen(location => {
        dispatch({
          type: 'check',
        });
      });
    },
  },
  effects : {
    *check({ }, { select, call, put }) {
      try {
        const currentUser = yield select(({ user }) => user.currentUser);
        if (window.$.isEmptyObject(currentUser)) {
          yield put(routerRedux.push('/login'));
        }
      } catch (err) {
        console.log(err);
      }
    },

浏览器console报错uncaught at sagaWithCatch,并且错误指向了下面的代码((anonymous function) @ user.js:30):

history.listen(function (location) {
        dispatch({
          type: 'check'
        });
      });

请教一下问题可能出在哪里?3Q

路由跳转写法的困惑routerRedux.push相关

在教程里,提到基于action的跳转的时候,有如下例子。
// Outside Effects
dispatch(routerRedux.push('/logout'));

// With query
routerRedux.push({
pathname: '/logout',
query: {
page: 2,
},
});
为什么带参数的跳转,不需要dispatch了呢?
感到迷茫,还请解惑。

动态路由 与 去除url _k 参数貌似有冲突

版本

"dva": "^1.2.1",
"history": "^4.6.1",
"react": "^15.4.0",

入口 index.js

import dva from 'dva';
import { createHashHistory } from 'history';
import { browserHistory, hashHistory, useRouterHistory } from 'dva/router';
import createLoading from 'dva-loading';
const app = dva({
  ...createLoading(),
  history: useRouterHistory(createHashHistory)({ queryKey: false }),
  onError (error) {
    console.error('app onError -- ', error);
  }
});

// 2. Plugins
// app.use({});

// 3. Model
app.model(require('./models/app'));

// app.model(require("./models/main"));

// 4. Router
app.router(require('./router'));

// 5. Start
app.start('#root');

路由 router.js

import React, { PropTypes } from 'react';
import { Router, Route, browserHistory } from 'dva/router';
import App from './routes/app/';

function Routers ({ history, app }) {
  const routes = [{
    path: '/',
    component: App,
    getIndexRoute (nextState, cb) {
      require.ensure([], require => {
        cb(null, { components: require('./routes/main/') });
      }, 'main');
    },
    childRoutes: [
      {
        path: '/console',
        getComponent (nextState, cb) {
          require.ensure([], require => {
            cb(null, require('./routes/console/'));
          }, 'console');
        }
      },
      {
        path: '*',
        getComponent (nextState, cb) {
          require.ensure([], require => {
            cb(null, require('./routes/error/'));
          }, 'error');
        }
      }
    ]
  }];
  return (<Router history={history} routes={routes} />);
}

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

effect 能够调用effect吗?

请问effect能够调用其他的effect吗?我尝试用put方法没有用。

另外,我想请问一下,effect要怎么通知到界面中去呢?
比如我登录成功,想在界面返回一个“登录成功”的消息弹窗,需要怎么实现?

谢谢。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.