-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathNavigationContext.tsx
54 lines (47 loc) · 1.03 KB
/
NavigationContext.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import React, {
createContext,
FunctionComponent,
AnchorHTMLAttributes,
DetailedHTMLProps,
} from "react"
import { UrlObject } from "url"
type Url = UrlObject | string
type DefaultLinkProps = DetailedHTMLProps<
AnchorHTMLAttributes<HTMLAnchorElement>,
HTMLAnchorElement
>
export interface LinkProps extends DefaultLinkProps {
className?: string
}
export interface GenericRouterOptions {
locale?: string
}
export interface GenericRouter {
push: (url: Url, as?: Url, options?: GenericRouterOptions) => void
back(): void
pathname: string
asPath: string
locale?: string
}
export interface NavigationContextProps {
LinkComponent: FunctionComponent<LinkProps>
router: GenericRouter
}
export const NavigationContext = createContext<NavigationContextProps>({
LinkComponent: (props) => (
<a className={props.className} {...props}>
{props.children}
</a>
),
router: {
push: () => {
// no-op
},
back: () => {
// no-op
},
pathname: "",
asPath: "",
locale: "",
},
})