umi4 history.push的参数发生了变化

1,377 阅读1分钟

在umi4中history.push的参数并不像以前那样传递参数了

  1. 在umi3里面,跳转时传参数写法​
// 带参数跳转到指定路由
history.push('/list?a=b&c=d#anchor');
history.push({
  pathname: '/list',
  search: '?a=b&c=d',
  hash: 'anchor',
});

​ 2. 在umi4里面,跳转时传参数写法​

// 带参数跳转到指定路由
history.push('/list?a=b&c=d#anchor');
history.push({
  pathname: '/list',
  search: '?a=b&c=d',
  hash: 'anchor',
});

​ 3. 如果想在umi4中传多个参数时跳转时传参数写法​

history.push('/library/identificationLibrary/information', record);

此时第二个参数便是想要传的值

const location = useLocation();

使用useLocation就可以收到你想要的值了