Magic Back Button
Redirects first-time visitors to the homepage; otherwise, respects browser history.
About
The Magic Back button is designed to prevent users from unintentionally leaving your site. When a user directly visits a page with a back button (i.e., their first visit), clicking the button will redirect them to the homepage. However, if they navigate to the page from another part of the site, the button respects the browser's history and behaves like a normal back button, without disrupting the browser's history records.
This component is built on top of React Page Tracker . before using this component.
Try opening this page link in a new tab,
and you’ll notice the button will navigate directly to the homepage. (router.push('/'))
However, if you navigate to this page from another component,
the button will simply go back to the previous page. (router.back())
Installation
Run the following command
pnpm dlx @shadext/cli add magic-back-button
Usage
Custom your back link
back to /docs when you first visit this page.