Started coding at the age of 13, now a professional software engineer and Scrum Master, creating and maintaining enterprise solutions. Eat - Sleep - Code - Lift - Repeat 💪🏾
Could you please be more specific?
To help you, the following information would be necessarry:
How do you route? (React-Router, NextJS router, ...)
Do you want to go back via history or push the URL to the history? (adds a new entry to the browsing history)
What do you expect from a "generic custom" back button?
Most of the time it is sufficient to route back (depending on answers to the questions above) in the onClick event.
thanks Robin for instant reply,
i am using React-Router.
and want to go back via history.
have to place one custom button in header component and whenever i will go on some page have to come back on render page. just like any browser back arrow works.
Started coding at the age of 13, now a professional software engineer and Scrum Master, creating and maintaining enterprise solutions. Eat - Sleep - Code - Lift - Repeat 💪🏾
First, use the HOC withRouter to be able to get the history object in via the properties (destructuring history and location in this example).
Then call .push() with the path you want to navigate to as parameter.
I don't recommend the second way, but here is another one: history.goBack().
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Could you please be more specific?
To help you, the following information would be necessarry:
What do you expect from a "generic custom" back button?
Most of the time it is sufficient to route back (depending on answers to the questions above) in the onClick event.
thanks Robin for instant reply,
i am using React-Router.
and want to go back via history.
have to place one custom button in header component and whenever i will go on some page have to come back on render page. just like any browser back arrow works.
You can use the React Training documentation as a good starting point.
Normally you would to something like this to navigate via anchors:
But as you want to route via code, you would want to do something like this:
First, use the HOC
withRouter
to be able to get thehistory
object in via the properties (destructuringhistory
andlocation
in this example).Then call
.push()
with the path you want to navigate to as parameter.I don't recommend the second way, but here is another one:
history.goBack()
.