ant design Pro Jump route - Jump arguments

Recent use ant design Pro project encountered problems routing jump,
a jump to the beginning to create problems encountered create pages
this article full of dry Oh
My first jump of the path is written in modal in
the Code

routerRedux Jump routing / router

import router from ‘umi/router’;
import { routerRedux } from ‘dva/router’;

Jump route with no arguments

The first to use import { routerRedux } from 'dva/router';
modal in
Here Insert Picture Description
and then click the Create button to jump in the js
Here Insert Picture Description

Jump routing parameters id

  • Jump to write in the same path or modal in
  • Here Insert Picture Description
    First of all we have to be changed in the local routing configuration
    Here Insert Picture Description
    in js in the same manner dispatch call
    Here Insert Picture Description
    in create pages
	componentDidMount () {
	    console.log(this.props.match.params.id)
	}

id get the value after the jump

Jump data routing parameters

modal likewise
Here Insert Picture Description
use json.stringify first destination analyzing
router.config.js in
Here Insert Picture Description
the event of the same to create click
Here Insert Picture Description
the create pages

	componentDidMount () {
	    console.log(this.props.match.params.data)
	}

Here Insert Picture Description
The object needs to be converted into

	componentDidMount () {
	    console.log(JSON.parse(this.props.match.params.data))
	}

Here Insert Picture Description

以下的方法中router中都不需要配置

params parameter passing jumps (not recommended, get less than the parameter value after refresh)

Here Insert Picture Description

  // 创建
  onCreate = () => {
   
    this.props.dispatch(routerRedux.push({
      pathname: '/api-manage/create-sub-system',
      params: {
        id: 6,
        value: 'lala',
      }
    }))
  };

Page created by
this.props.locationthe value of the acquired
Here Insert Picture Description
but not to get the value of params after refresh the current page
Here Insert Picture Description
but can be seen by comparing the above two query has always existed, so we can pass parameters to be routed through query

query路由传参(推荐)

Here Insert Picture Description

 // 创建
  onCreate = () => {
    this.props.dispatch(routerRedux.push({
      pathname: '/api-manage/create-sub-system',
      query: {
        id: 6,
        value: 'lala',
      }
    }))
  };

Page created by this.props.location
Here Insert Picture Description

Link routed jump (highly recommended)

import Link from 'umi/link';
Here Insert Picture Description

import Link from 'umi/link';
<Link to={{
     pathname: '/api-manage/create-sub-system',
      query: {
        id: 6,
        value: 'lala',
      }
    }}>
      <Button
        style={{ marginLeft: 8 }}
        type="primary"
      // onClick={this.onCreate}
      >
        <Icon type="plus" />
        创建
    </Button>
 </Link>

create a page this.props.locationto get value
Here Insert Picture Description

Like query and a state of way, but not the same property, the passed parameter state is encrypted, pass query parameters are public,

Here Insert Picture Description
Here Insert Picture Description
以上通过过r Link parmas state 或者routerRedux.push方式的路由跳转传参都可以使用js中的 this.props.history.push方式

Published 47 original articles · won praise 42 · Views 140,000 +

Guess you like

Origin blog.csdn.net/zm_miner/article/details/96356835