第一种
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: '/要跳转的路径', state: { key值:val值 } });
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) // 传递过来的所有参数
console.log(this.props.location.state.key值) // val值
第五种
let href = `/aaa?taskId=${encodeURI(taskId)}&url=${encodeURI(url)}`;
const a = document.createElement('a');
a.setAttribute('href', href);
a.setAttribute('target', '_blank'); //是不是新开页面
a.click();
网友评论