I'm trying to use Next.js router to redirect unauthorized users from accessing certain pages that are wrapped inside the AdminLayout
component, but I got this error.
Error: No router instance found. You should only use "next/router" inside the client side of your app.
// 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);
Any way to fix this?