try custom router
This commit is contained in:
parent
3db64a4965
commit
ee3b996a43
|
|
@ -1,6 +1,6 @@
|
||||||
import 'preact/debug'
|
import 'preact/debug'
|
||||||
import { render } from 'preact'
|
import { render } from 'preact'
|
||||||
import Router from 'preact-router'
|
import Router, { RouterProps } from 'preact-router'
|
||||||
import { Home } from '@/pages/Home'
|
import { Home } from '@/pages/Home'
|
||||||
import { Posts } from '@/pages/Posts'
|
import { Posts } from '@/pages/Posts'
|
||||||
import Post from '@/pages/Post'
|
import Post from '@/pages/Post'
|
||||||
|
|
@ -10,17 +10,30 @@ import { MantineProvider } from '@mantine/styles'
|
||||||
import { Box } from '@mantine/core'
|
import { Box } from '@mantine/core'
|
||||||
import { theme } from '@/theme'
|
import { theme } from '@/theme'
|
||||||
|
|
||||||
|
const MY_FOLDER = '/orionreed'
|
||||||
|
class SubfolderRouter extends Router {
|
||||||
|
render(props: RouterProps, state: any) {
|
||||||
|
if (state.url.indexOf(MY_FOLDER) === 0) {
|
||||||
|
state = {
|
||||||
|
...state,
|
||||||
|
url: state.url.substr(MY_FOLDER.length),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return super.render(props, state)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function App() {
|
export function App() {
|
||||||
return (
|
return (
|
||||||
<MantineProvider withGlobalStyles withNormalizeCSS theme={theme}>
|
<MantineProvider withGlobalStyles withNormalizeCSS theme={theme}>
|
||||||
<Box mb="xl">
|
<Box mb="xl">
|
||||||
<Router>
|
<SubfolderRouter>
|
||||||
<Home path="/" />
|
<Home path="/" />
|
||||||
<Posts path="/posts" />
|
<Posts path="/posts" />
|
||||||
<Post path="/posts/:title" />
|
<Post path="/posts/:title" />
|
||||||
<Stream path="/stream" />
|
<Stream path="/stream" />
|
||||||
<NotFound default />
|
<NotFound default />
|
||||||
</Router>
|
</SubfolderRouter>
|
||||||
</Box>
|
</Box>
|
||||||
</MantineProvider>
|
</MantineProvider>
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue