【发布时间】:2021-01-07 17:53:13
【问题描述】:
我想通过 history.push 与分页相关的部分 url 发送状态到登录页面。 但是我不知道如何在 Login 中输入它,所以 typescript 会理解 state 到底包含什么。
我收到的错误:
Property 'redirectUrl' does not exist on type '{}'
if (!isAuthorized) {
history.push({ pathname: AppRoute.login, state: { redirectUrl: 'page=2' } });
return;
}
登录页面
const history = useHistory();
const redirectState = history?.location?.state;
if (isAuthorized) {
history.push({ pathname: AppRoute.home, search: redirectState?.redirectUrl })
return;
}
【问题讨论】:
标签: reactjs typescript react-router react-router-dom