【js】window.location跳转的传参和获取参数的写法

state是要传的参数 url是地址 使用window.history.pushState进行跳转 window.location.href=url是为了如果想在当前页面再跳一下当前页面

const state = { id: item.info.id };
const url = '/paasportal/api-service-platform/home/apiDetail';
 window.history.pushState(state, '', url);
 window.location.href = url;

用window.history.state获取传过来的state参数

const state = window.history.state;
const id = state ? state.id : undefined;
console.log(id);

你可能感兴趣的:(js,javascript,前端,开发语言)