Skip to content

Commit

Permalink
fix(apps): add 404 page and redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfreska committed Oct 31, 2024
1 parent 675bd8f commit d4af4c3
Show file tree
Hide file tree
Showing 11 changed files with 105 additions and 8 deletions.
7 changes: 7 additions & 0 deletions .changeset/warm-moles-care.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'hostd': minor
'renterd': minor
'walletd': minor
---

Invalid and not found routes now redirect to the home page.
18 changes: 18 additions & 0 deletions apps/hostd/components/Redirect/Layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {
HostdAuthedLayout,
HostdAuthedPageLayoutProps,
} from '../HostdAuthedLayout'
import { HostdSidenav } from '../HostdSidenav'
import { routes } from '../../config/routes'
import { useDialog } from '../../contexts/dialog'

export const Layout = HostdAuthedLayout
export function useLayoutProps(): HostdAuthedPageLayoutProps {
const { openDialog } = useDialog()
return {
title: 'Home',
routes,
sidenav: <HostdSidenav />,
openSettings: () => openDialog('settings'),
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { routes } from '../../config/routes'
import { useEffect } from 'react'
import { useRouter } from 'next/router'

export function Home() {
export function Redirect({ route }: { route: string }) {
const router = useRouter()

useEffect(() => {
router.replace(routes.buckets.index)
}, [router])
router.replace(route)
}, [router, route])

return <div />
}
10 changes: 10 additions & 0 deletions apps/hostd/pages/404.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Redirect } from '../components/Redirect'
import { Layout, useLayoutProps } from '../components/Redirect/Layout'
import { routes } from '../config/routes'

export default function Page() {
return <Redirect route={routes.home} />
}

Page.Layout = Layout
Page.useLayoutProps = useLayoutProps
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const Layout = RenterdAuthedLayout
export function useLayoutProps(): RenterdAuthedPageLayoutProps {
const { openDialog } = useDialog()
return {
title: 'Dashboard',
title: 'Home',
routes,
sidenav: <RenterdSidenav />,
openSettings: () => openDialog('settings'),
Expand Down
12 changes: 12 additions & 0 deletions apps/renterd/components/Redirect/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { useEffect } from 'react'
import { useRouter } from 'next/router'

export function Redirect({ route }: { route: string }) {
const router = useRouter()

useEffect(() => {
router.replace(route)
}, [router, route])

return <div />
}
10 changes: 10 additions & 0 deletions apps/renterd/pages/404.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Redirect } from '../components/Redirect'
import { Layout, useLayoutProps } from '../components/Redirect/Layout'
import { routes } from '../config/routes'

export default function Page() {
return <Redirect route={routes.buckets.index} />
}

Page.Layout = Layout
Page.useLayoutProps = useLayoutProps
7 changes: 4 additions & 3 deletions apps/renterd/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Home } from '../components/Home'
import { Layout, useLayoutProps } from '../components/Home/Layout'
import { Redirect } from '../components/Redirect'
import { Layout, useLayoutProps } from '../components/Redirect/Layout'
import { routes } from '../config/routes'

export default function Page() {
return <Home />
return <Redirect route={routes.buckets.index} />
}

Page.Layout = Layout
Expand Down
18 changes: 18 additions & 0 deletions apps/walletd/components/Redirect/Layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {
WalletdAuthedLayout,
WalletdAuthedPageLayoutProps,
} from '../WalletdAuthedLayout'
import { WalletdSidenav } from '../WalletdSidenav'
import { routes } from '../../config/routes'
import { useDialog } from '../../contexts/dialog'

export const Layout = WalletdAuthedLayout
export function useLayoutProps(): WalletdAuthedPageLayoutProps {
const { openDialog } = useDialog()
return {
title: 'Home',
routes,
sidenav: <WalletdSidenav />,
openSettings: () => openDialog('settings'),
}
}
12 changes: 12 additions & 0 deletions apps/walletd/components/Redirect/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { useEffect } from 'react'
import { useRouter } from 'next/router'

export function Redirect({ route }: { route: string }) {
const router = useRouter()

useEffect(() => {
router.replace(route)
}, [router, route])

return <div />
}
10 changes: 10 additions & 0 deletions apps/walletd/pages/404.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Redirect } from '../components/Redirect'
import { Layout, useLayoutProps } from '../components/Redirect/Layout'
import { routes } from '../config/routes'

export default function Page() {
return <Redirect route={routes.home} />
}

Page.Layout = Layout
Page.useLayoutProps = useLayoutProps

0 comments on commit d4af4c3

Please sign in to comment.