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
and then click the Create button to jump in the js
Jump routing parameters id
- Jump to write in the same path or modal in
First of all we have to be changed in the local routing configuration
in js in the same manner dispatch call
in create pages
componentDidMount () {
console.log(this.props.match.params.id)
}
id get the value after the jump
Jump data routing parameters
modal likewise
use json.stringify first destination analyzing
router.config.js in
the event of the same to create click
the create pages
componentDidMount () {
console.log(this.props.match.params.data)
}
The object needs to be converted into
componentDidMount () {
console.log(JSON.parse(this.props.match.params.data))
}
以下的方法中router中都不需要配置
params parameter passing jumps (not recommended, get less than the parameter value after refresh)
// 创建
onCreate = () => {
this.props.dispatch(routerRedux.push({
pathname: '/api-manage/create-sub-system',
params: {
id: 6,
value: 'lala',
}
}))
};
Page created by
this.props.location
the value of the acquired
but not to get the value of params after refresh the current page
but can be seen by comparing the above two query has always existed, so we can pass parameters to be routed through query
query路由传参(推荐)
// 创建
onCreate = () => {
this.props.dispatch(routerRedux.push({
pathname: '/api-manage/create-sub-system',
query: {
id: 6,
value: 'lala',
}
}))
};
Page created by this.props.location
Link routed jump (highly recommended)
import Link from 'umi/link';
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.location
to get value
Like query and a state of way, but not the same property, the passed parameter state is encrypted, pass query parameters are public,
以上通过过r Link parmas state 或者routerRedux.push方式的路由跳转传参都可以使用js中的 this.props.history.push方式