Next.js Discord

Discord Forum

Navigation Guard

Answered
North Pacific hake posted this in #help-forum
Open in Discord
North Pacific hakeOP
Please, I've noticed this issue with React, and now it's same for NextJs, though Middleware have somehow solved the issue,

So the issue is that, For instance a user clicks on sign out, and his/her details got cleared from the browser, redirecting the user to the Sign in page, if you try to click on the browser back arrow, it'll still navigate the user to the previous page or page page it in the browse route history, except you refresh the page, or maybe the page is the kind that makes request on mount which would then detect from the request response that it's an unauthorized user,

So I want to ask if there's a solution to that,
Just like VueJs has something like Router.beforeEach, I'd really appreciate a feedback on this,

Thank you
Answered by B33fb0n3
it only refreshes the content that is new. There is no redirection when using router.fresh(). So you would need to do something like
router.push("/your/path");
router.refresh();
// or other way around (test it):
router.refresh();
router.push("/your/path");
View full answer

5 Replies

@North Pacific hake But I thought that router.refresh() only refresh the window, without redirecting to a new page
it only refreshes the content that is new. There is no redirection when using router.fresh(). So you would need to do something like
router.push("/your/path");
router.refresh();
// or other way around (test it):
router.refresh();
router.push("/your/path");
Answer
Happy to help