fix: Preact router and BASE_URL
This commit is contained in:
+11
-6
@@ -1,6 +1,8 @@
|
||||
import Router 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 { HomePage } from './pages/Home'
|
||||
@@ -21,27 +23,30 @@ const Redirect = ({ to }: { to: 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 (
|
||||
<Router url={url}>
|
||||
<HomePage
|
||||
// @ts-ignore
|
||||
path="/"
|
||||
path={pbu('/')}
|
||||
/>
|
||||
<LoginPage
|
||||
// @ts-ignore
|
||||
path="/login"
|
||||
path={pbu('/login')}
|
||||
/>
|
||||
<ProfilePage
|
||||
// @ts-ignore
|
||||
path="/profile"
|
||||
path={pbu('/profile')}
|
||||
/>
|
||||
<ProblemPage
|
||||
// @ts-ignore
|
||||
path="/problem/:id"
|
||||
path={pbu('/problem/:id')}
|
||||
/>
|
||||
<AdminPage
|
||||
// @ts-ignore
|
||||
path="/admin"
|
||||
path={pbu('/admin')}
|
||||
/>
|
||||
<Redirect
|
||||
// @ts-ignore
|
||||
|
||||
@@ -10,9 +10,9 @@ export default (url: string): RenderedPage => {
|
||||
|
||||
const html = renderToString(
|
||||
<MetadataContext.Provider value={metadata}>
|
||||
{/* <ServerContext.Provider value={true}> */}
|
||||
<App url={url} />
|
||||
{/* </ServerContext.Provider> */}
|
||||
<ServerContext.Provider value={true}>
|
||||
<App url={url} />
|
||||
</ServerContext.Provider>
|
||||
</MetadataContext.Provider>
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user