mirror of
https://github.com/Stone-Red-Code/website.git
synced 2026-09-05 23:43:37 +02:00
feat(resources): open current path on page load
This commit is contained in:
@@ -1,9 +1,14 @@
|
||||
import { WindowLocation } from "@reach/router"
|
||||
import React, { FC, PropsWithChildren, useMemo } from "react"
|
||||
|
||||
function appendSlashToPath(path: string): string {
|
||||
return path.endsWith("/") ? path : `${path}/`
|
||||
}
|
||||
|
||||
export interface ILocationContextInterface {
|
||||
location: WindowLocation | void
|
||||
isHome: boolean
|
||||
isMatchingPath: (path: string) => boolean
|
||||
}
|
||||
|
||||
interface ILocationProviderProps {
|
||||
@@ -21,6 +26,11 @@ export const LocationProvider: FC<
|
||||
() => ({
|
||||
location,
|
||||
isHome: location ? location.pathname === "/" : false,
|
||||
isMatchingPath: (path: string) => {
|
||||
return location
|
||||
? appendSlashToPath(location.pathname).startsWith(path)
|
||||
: false
|
||||
},
|
||||
}),
|
||||
[location]
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user