From fe0fa6c99329224c9251929c5cdd236edaa32083 Mon Sep 17 00:00:00 2001 From: Juliette Lamarche Date: Sat, 20 Jul 2024 13:28:11 -0400 Subject: [PATCH] fix(404): redirect --- packages/web/public/404.html | 45 ++++--------------------------- packages/web/src/routes/index.tsx | 29 +++++--------------- 2 files changed, 11 insertions(+), 63 deletions(-) diff --git a/packages/web/public/404.html b/packages/web/public/404.html index 57fae12..bcde720 100644 --- a/packages/web/public/404.html +++ b/packages/web/public/404.html @@ -4,46 +4,11 @@ Single Page Apps for GitHub Pages diff --git a/packages/web/src/routes/index.tsx b/packages/web/src/routes/index.tsx index d79bd6c..d5884f3 100644 --- a/packages/web/src/routes/index.tsx +++ b/packages/web/src/routes/index.tsx @@ -1,32 +1,15 @@ -import { createFileRoute, useSearch } from '@tanstack/react-router' -import { useEffect } from 'react' +import { createFileRoute, Navigate, useSearch } from '@tanstack/react-router' import { z } from 'zod' export const Route = createFileRoute('/')({ component: Component, - validateSearch: z.object({ path: z.string().catch('') }), + validateSearch: z.object({ + to: z.string().catch('/notes'), + }), }) -// this is to support github pages -// https://github.com/rafgraph/spa-github-pages/blob/gh-pages/index.html#L21-L42 -function decodePath(path: string) { - return path - .slice(1) - .split('&') - .map(function (s) { - return s.replace(/~and~/g, '&') - }) - .join('?') -} - function Component() { - const { path } = useSearch({ from: Route.fullPath }) - const to = `${import.meta.env.BASE_URL}/${path ? decodePath(path) : '/notes'}` - // __AUTO_GENERATED_PRINT_VAR_START__ + const { to } = useSearch({ from: Route.fullPath }) console.log('Component to: %s', to) // __AUTO_GENERATED_PRINT_VAR_END__ - useEffect(() => { - console.log('effect') - window.location.replace(to) - }, [to]) - return null + return }