feat: back redirection

This commit is contained in:
anmolsinghbhatia 2023-05-04 12:13:09 +05:30
parent a2825208b8
commit f0397ef2b5
2 changed files with 17 additions and 1 deletions

View File

@ -17,7 +17,17 @@ const Breadcrumbs = ({ children }: BreadcrumbsProps) => {
<button
type="button"
className="grid h-8 w-8 flex-shrink-0 cursor-pointer place-items-center rounded border border-brand-base text-center text-sm hover:bg-brand-surface-1"
onClick={() => router.back()}
onClick={() => {
const lastTenUrls = JSON.parse(localStorage.getItem("lastTenUrls") || "[]");
if (lastTenUrls.length > 0) {
const url = lastTenUrls[1];
lastTenUrls.splice(0, 2);
localStorage.setItem("lastTenUrls", JSON.stringify(lastTenUrls));
router.push(url);
} else {
router.push("/");
}
}}
>
<ArrowLeftIcon className="h-3 w-3" />
</button>

View File

@ -31,6 +31,12 @@ NProgress.configure({ showSpinner: false });
Router.events.on("routeChangeStart", NProgress.start);
Router.events.on("routeChangeError", NProgress.done);
Router.events.on("routeChangeComplete", NProgress.done);
Router.events.on("routeChangeComplete", () => {
const urls = JSON.parse(localStorage.getItem("lastTenUrls") || "[]");
urls.unshift(Router.asPath);
const trimmedUrls = urls.slice(0, 10);
localStorage.setItem("lastTenUrls", JSON.stringify(trimmedUrls));
});
function MyApp({ Component, pageProps }: AppProps) {
return (