Skip to content
Source
Sign inSign up
TanStack/router
Open History to see the last commit

routerContext.tsx

26 lines552 Bytes

1import * as Solid from 'solid-js'
2import type { AnyRouter } from '@tanstack/router-core'
3​
4declare global {
5 interface Window {
6 __TSR_ROUTER_CONTEXT__?: Solid.Context<AnyRouter>
7 }
8}
9​
10const routerContext = Solid.createContext<AnyRouter>(
11 null as unknown as AnyRouter,
13​
14export function getRouterContext() {
15 if (typeof document === 'undefined') {
16 return routerContext
17 }
18​
19 if (window.__TSR_ROUTER_CONTEXT__) {
20 return window.__TSR_ROUTER_CONTEXT__
21 }
22​
23 window.__TSR_ROUTER_CONTEXT__ = routerContext as any
24​
25 return routerContext