next-router-mock icon indicating copy to clipboard operation
next-router-mock copied to clipboard

`router.back` support

Open himself65 opened this issue 2 years ago • 4 comments

himself65 avatar Feb 24 '23 23:02 himself65

If router.back was supported, what kind of use-case would you want? Like, maybe push should keep a stack of URLs, and router.back would pop from the stack? Any other scenarios to support?

scottrippey avatar Feb 25 '23 00:02 scottrippey

If router.back was supported, what kind of use-case would you want? Like, maybe push should keep a stack of URLs, and router.back would pop from the stack? Any other scenarios to support?

In my case, I implement a react hook that is based on the next-router. And When you type something wrong. It will force redirect the page to the expected main page, which uses router.replace. But most cases, it will use router.push to track the user's history.

That's why I need router.back because I want to see if the browser history is working as expected.

himself65 avatar Feb 26 '23 14:02 himself65

If router.back was supported, what kind of use-case would you want? Like, maybe push should keep a stack of URLs, and router.back would pop from the stack? Any other scenarios to support?

In my case, I implement a react hook that is based on the next-router. And When you type something wrong. It will force redirect the page to the expected main page, which uses router.replace. But most cases, it will use router.push to track the user's history.

That's why I need router.back because I want to see if the browser history is working as expected.

https://github.com/toeverything/AFFiNE/blob/67df422d60a7e42f3287110d6fcdb5a2d515612a/apps/rem/src/hooks/tests/use-router-helper.spec.ts#L52-L55

himself65 avatar Feb 26 '23 14:02 himself65

I will try to work on this recently

himself65 avatar Mar 08 '23 23:03 himself65