Skip to content

Instantly share code, notes, and snippets.

@helloncanella
Created October 16, 2019 17:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save helloncanella/d452fe8241d34d1784ca66c61525496d to your computer and use it in GitHub Desktop.
Save helloncanella/d452fe8241d34d1784ca66c61525496d to your computer and use it in GitHub Desktop.
import _ from "lodash"
import useRouter from "use-react-router"
import { join } from "path"
import { matchPath } from "react-router-dom"
export default function useMatchPath(path) {
const { location } = useRouter()
const pathname = _.get(location, "pathname")
const match = matchPath(pathname, { path: join("(.*)?", path) }) || {}
return _.get(match, "params", {})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment