第一种
window. location. href = '/app?id=1' ;
import querystring from 'querystring' ;
console. log ( querystring. parse ( location. search. replace ( '?' , '' ) ) . id) ;
第二种
import { withRouter } from 'dva/router' ;
class App extends Component {
...
go = ( ) => {
this . props. history. push ( { pathname: '/app' , state: { id:12 } } ) ;
}
}
export default withRouter ( connect ( ) ( App) ) ;
console. log ( this . props. location. state. id) ;
第三种
import { routerRedux } from 'dva/router' ;
this . props. dispatch ( routerRedux. push ( `/app/template/editor?id= ${ myId} ` ) ) ;
this . props. dispatch ( routerRedux. push ( {
pathname: '/app/xxx' ,
search: `id= ${ myId} ` ,
} ) )
console. log ( this . props. location. xxx) ;
第四种
import { Link } from 'dva/router' ;
< Link to= {
{
pathname: `/要跳转的路径` ,
state: { key值:val值}
}
} >
console. log ( this . props. location. state. key值)
第五种
let href = `/aaa?taskId= ${ encodeURI ( taskId) } &url= ${ encodeURI ( url) } ` ;
const a = document. createElement ( 'a' ) ;
a. setAttribute ( 'href' , href) ;
a. setAttribute ( 'target' , '_blank' ) ;
a. click ( ) ;