I have a page for posting projects and I want cancel to go back to the previous page but only if it's a page that belongs to my app.
For example, say I went to the post creator page from the User Settings page, then it'd look something like this.
User Settings -> Post Creator -> hit cancel -> call router.back() -> go back to User Settings Page
This can be done by using the useRouter hook and then calling router.back()
Butttt what if for some reason the Post Creator page is visited on a fresh tab. Is there a way to automatically redirect to the home page if the router history does not contain my app?
For example,
Post Creator -> hit cancel -> No history containing current app -> redirect to home page.
I know this is a silly edge case but I'm wondering if it can be done.