feat: create basic router

This commit is contained in:
Valerio Ageno
2024-05-11 15:08:49 +02:00
parent df80756c44
commit 73c94e5fbb
30 changed files with 686 additions and 105 deletions
@@ -0,0 +1,20 @@
import * as React from 'react'
import type { Router } from '../router'
const routerContext = React.createContext<Router>(null!)
const ROUTER_DOM_CONTEXT = '__TUONO_ROUTER__CONTEXT__'
export function getRouterContext(): any {
if (typeof document === 'undefined') {
return routerContext
}
if (window[ROUTER_DOM_CONTEXT as any]) {
return window[ROUTER_DOM_CONTEXT as any]
}
window[ROUTER_DOM_CONTEXT as any] = routerContext as any
return routerContext
}