fix: Preact router and BASE_URL
This commit is contained in:
+11
-6
@@ -1,6 +1,8 @@
|
|||||||
import Router from 'preact-router'
|
import Router from 'preact-router'
|
||||||
import { route } from 'preact-router'
|
import { route } from 'preact-router'
|
||||||
import { useEffect } from 'preact/hooks'
|
import { useContext, useEffect } from 'preact/hooks'
|
||||||
|
import { prependBaseUrl } from './api'
|
||||||
|
import { ServerContext } from './hooks'
|
||||||
import { AdminPage } from './pages/Admin'
|
import { AdminPage } from './pages/Admin'
|
||||||
|
|
||||||
import { HomePage } from './pages/Home'
|
import { HomePage } from './pages/Home'
|
||||||
@@ -21,27 +23,30 @@ const Redirect = ({ to }: { to: string }) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const App = ({ url }: { url?: string }) => {
|
export const App = ({ url }: { url?: string }) => {
|
||||||
|
// during server side rendering don't prepend the BASE_URL
|
||||||
|
const pbu = useContext(ServerContext) ? (s: string) => s : prependBaseUrl
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Router url={url}>
|
<Router url={url}>
|
||||||
<HomePage
|
<HomePage
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
path="/"
|
path={pbu('/')}
|
||||||
/>
|
/>
|
||||||
<LoginPage
|
<LoginPage
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
path="/login"
|
path={pbu('/login')}
|
||||||
/>
|
/>
|
||||||
<ProfilePage
|
<ProfilePage
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
path="/profile"
|
path={pbu('/profile')}
|
||||||
/>
|
/>
|
||||||
<ProblemPage
|
<ProblemPage
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
path="/problem/:id"
|
path={pbu('/problem/:id')}
|
||||||
/>
|
/>
|
||||||
<AdminPage
|
<AdminPage
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
path="/admin"
|
path={pbu('/admin')}
|
||||||
/>
|
/>
|
||||||
<Redirect
|
<Redirect
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
|
|||||||
@@ -10,9 +10,9 @@ export default (url: string): RenderedPage => {
|
|||||||
|
|
||||||
const html = renderToString(
|
const html = renderToString(
|
||||||
<MetadataContext.Provider value={metadata}>
|
<MetadataContext.Provider value={metadata}>
|
||||||
{/* <ServerContext.Provider value={true}> */}
|
<ServerContext.Provider value={true}>
|
||||||
<App url={url} />
|
<App url={url} />
|
||||||
{/* </ServerContext.Provider> */}
|
</ServerContext.Provider>
|
||||||
</MetadataContext.Provider>
|
</MetadataContext.Provider>
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user