I have a component which is leveraging history.push('/login')
after one has registered for my app.
However I am getting this behavior where the url in the address bar is changing but I am not seeing the new component. So I read the docs regarding componentDidUpdate and it states:
componentDidUpdate() is invoked immediately after updating occurs. This method is not called for the initial render.
Use this as an opportunity to operate on the DOM when the component has been updated.
I would think it would be something like this to start with:
componentDidUpdate(prevProps, nextProps) {
if (this.props.location.pathname !== nextProps.props.location.pathname){
this.props.location.pathname
/* or some other black magic here */
}
}
But then I remembered you're not supposed to change props directly... How would I go about this?
UPDATE
As per Sunil he mentioned I might have a HOC
at a the very top level,
Because I was originally using Next.js they used a page navigation and I because of that I was doing this:
Folder structure:
Then wrapping a HOC around my client component:
import 'semantic-ui-css/semantic.min.css'
import RegisterForm from '../components/Register/RegisterForm.jsx'
import '../components/Register/Register.css'
import { withRouter } from "react-router-dom";
const Register = (props) => (<>
<RegisterForm {...props} />
</>)
export default withRouter(Register)