feat(resources): open current path on page load

This commit is contained in:
Jean-Philippe Sirois
2019-11-08 19:22:33 -08:00
parent 3b3a68698f
commit 3f94a780be
3 changed files with 32 additions and 0 deletions
+10
View File
@@ -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]
)