【发布时间】:2020-09-18 06:42:37
【问题描述】:
我正在尝试使用 Next.js 路由器重定向未经授权的用户访问包装在 AdminLayout 组件中的某些页面,但我收到了这个错误。
错误:未找到路由器实例。你应该只使用“下一个/路由器” 在应用的客户端内。
// Other imports
import Router from "next/router";
class AdminLayout extends React.Component {
render() {
const { currentUser } = this.props;
if (currentUser === undefined) {
console.log(currentUser);
return null;
}
if (currentUser == null) {
console.log(currentUser);
//this is how I tried to redirect
Router.replace("/admin/login");
}
return (
// Other irrelevant code
);
}
}
const mapStateToProps = (state) => ({
currentUser: state.user.currentUser,
});
export default connect(mapStateToProps)(AdminLayout);
有什么办法解决这个问题?
【问题讨论】:
标签: reactjs redux next.js next-router