Fixed layout and routing

This commit is contained in:
Patrick Alvin Alcala 2025-09-24 17:55:40 +08:00
parent c57727e20a
commit ddff738d2e
5 changed files with 54 additions and 26 deletions

View file

@ -1,27 +1,14 @@
import './Layout.sass'
import { lazy } from 'solid-js'
import { render } from 'solid-js/web'
import { Router } from '@solidjs/router'
import type { JSXElement } from 'solid-js'
const root = document.getElementById('root')
interface Props {
children: JSXElement
}
const routes = [
{
path: '/',
component: lazy(() => import('../pages/IndexPage/Index.tsx')),
},
{
path: '/main',
component: lazy(() => import('../pages/MainPage/Main.tsx')),
},
{
path: '/register',
component: lazy(() => import('../pages/RegisterPage/Register.tsx')),
},
{
path: '/login',
component: lazy(() => import('../pages/LoginPage/Login.tsx')),
},
]
render(() => <Router>{routes}</Router>, root!)
export default (props: Props) => {
return (
<>
<div class="layout">{props.children}</div>
</>
)
}

33
src/routers/router.tsx Normal file
View file

@ -0,0 +1,33 @@
import { lazy } from 'solid-js'
import Layout from '../layouts/Layout.tsx'
const routes = [
{
path: '/',
component: (props: any) => <Layout>{props.children}</Layout>,
children: [
{
path: '/',
component: lazy(() => import('../pages/IndexPage/Index.tsx')),
},
{
path: '/main',
component: lazy(() => import('../pages/MainPage/Main.tsx')),
},
{
path: '/register',
component: lazy(() => import('../pages/RegisterPage/Register.tsx')),
},
{
path: '/login',
component: lazy(() => import('../pages/LoginPage/Login.tsx')),
},
],
},
{
path: '**',
component: () => <div>404</div>,
},
]
export default routes