Skip to content

Commit

Permalink
Add fallback navigation when unable to go back
Browse files Browse the repository at this point in the history
  • Loading branch information
walidkayhan committed Feb 18, 2025
1 parent 38e00bf commit dee6380
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/app/src/components/Page/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import cn from 'classnames';
import { useRouter } from '@tanstack/react-router';
import { useRouter, useCanGoBack } from '@tanstack/react-router';
import { LuArrowLeft } from 'react-icons/lu';

import { Button } from 'app/components/shadcn/Button';
Expand All @@ -20,6 +20,8 @@ const Page = ({
withGoBackButton,
}: PageProps) => {
const navigate = useRouter();
const canGoBack = useCanGoBack();

return (
<div
className={cn(
Expand All @@ -30,10 +32,15 @@ const Page = ({
>
<div className="flex items-center justify-between mb-4 min-h-12">
<h1 className="text-3xl font-bold">{title}</h1>

{withGoBackButton && (
<Button
variant="outline"
onClick={() => navigate.history.back()}
onClick={() =>
canGoBack
? navigate.history.back()
: navigate({ to: '/' })
}
size="lg"
className="flex items-center justify-center"
>
Expand Down

0 comments on commit dee6380

Please sign in to comment.