score:1
Accepted answer
nextjs uses ssr, so during pre-rendering (ssr or ssg) you tried to access a router method push (this.props.router.push(loginpage.routepath)) which is not supported.
you should you use your following code in the componentdidmount
method
if (!this.loggedinuser) {
this.props.router.push(loginpage.routepath);
}
like as below
componentdidmount() {
this.loggedinuser = usermanager.getloggedinuser();
if (!this.loggedinuser) {
this.props.router.push(loginpage.routepath);
}
}
Source: stackoverflow.com
Related Query
- How to access NextJS Router in class component
- how to access router params in getInitialProps stateles component in nextjs
- how to pass object as params in Router.push() in nextjs and access that object in other component
- How to access props outside of a class component React
- How to access route params from a component other then the Router component
- How to access URL param to update component state in class component?
- How can I access a class component method in a function component?
- How to pass function from FUNCTIONAL to CLASS component and access it outside of render( without prop ), using context in react js?
- react, gatsby - how to access GraphQL query data in react class component
- How to call a react hook fetch request in a functional component to access data then pass to a class component to map?
- how to get access method dispatch() into component of class
- How to access param in parent component with React Router DOM
- How to listen to changes in router and force to a class component to re-render?
- How to access the state of a child component from a parent class
- How to access React router history object with component interface that has default custom hook specified
- How to access redux in a new react class component
- How to access component parameters from app.js in react router
- React: How can you access the class name of a parent component from a child without passing it down as props?
- How to access props from Parent Component inside the Child Class Component ? (specifically for componentDidMount)?
- React router v6 how to get current route in class component
- How to access passed data using router from one component to another ReactJS
- How can I access a component's class properties from another component with React?
- React Router how to change class name of an element in a component when route changes?
- How to access my redux state outside of the functional component or class component?
- How to render a component with props derivative from NextJS router
- How to access a function in a child class component from a stateless parent?
- How to access history in a component that is not in Router List?
- How to access component methods from “outside” in ReactJS?
- How do I access refs of a child component in the parent component
- How to access the "key" property from a reactjs component
More Query from same tag
- React - Handle modification of cell inside state's array
- Uable to make a req from one server to another - "Error: Request failed with status code 401"
- React + Webpack don't resolve file loaders
- React Compound Components type warning
- How do I change the background color of the body?
- Change signal color based on value fetch from API
- Unable to Edit the Material UI Textfields in React
- data is undefined although using async and await
- React js: fail to get specific product data when clicking on one product
- Reset the state of other component onClick using MUI in React
- Largest contentful paint is one big gatsby-background-image and very slow
- Is there any option in React-DnD, which enables drop targets based on drag object which intersects over 50% of area in drop target?
- How to hide a column on Material UI based on certain criteria?
- Check if a condition is met before pushing a property into array ReactJS
- React-How can I prevent going back to login page after login?
- Collapse navbar sooner then 576px
- React: useState(): Fetching data during an ongoing fetch does not work
- Iterating over a nested array in api - ReactJS
- ReactDOM does not render a simple div
- Error creating contexts in React Typescript
- React with Firebase Auth: How to set Persistence?
- How to I apply a custom style for a third-party component in a single React component without affecting its style in other components?
- Fetch foreign key object instead of ID in React from Django API
- React, setting initial value to input element
- Render React components which require styles on server
- Trying to filter array of object based on returned values
- How to get Stripe Elements to dynamically change styles with Next-themes
- How to let react electron ignore undefined error?
- loading state never get true??(React - Redux)
- How to define propTypes for a Component that only passes props to a Child