Skip to content

Commit

Permalink
Update main.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
tannerlinsley committed Dec 8, 2022
1 parent e7d9969 commit d9cc91a
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions examples/react/kitchen-sink-single-file/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ const dashboardRoute = rootRoute.createRoute({
path: 'dashboard',
loader: async () => {
console.log('Fetching all invoices...')

return {
invoices: await fetchInvoices(),
}
Expand Down Expand Up @@ -660,16 +661,29 @@ const expensiveRoute = rootRoute.createRoute({

const authenticatedRoute = rootRoute.createRoute({
path: 'authenticated',
beforeLoad: () => {
if (router.options.context.auth.status === 'loggedOut') {
throw router.navigate({
onLoadError: (error: Error) => {
if (error.message === 'Not logged in') {
router.navigate({
to: loginRoute.id,
search: {
redirect: router.state.location.href,
// Use latestLocation (not currentLocation) to get the live url
// (as opposed to the committed url, which is technically async
// and resolved after the pending state)
redirect: router.state.latestLocation.href,
},
})
}
},
beforeLoad: () => {
if (router.options.context.auth.status === 'loggedOut') {
throw new Error('Not logged in')
}
},
loader: () => {
console.log()
return {}
},

component: () => {
const auth = useAuth()

Expand Down

0 comments on commit d9cc91a

Please sign in to comment.