Last active
February 6, 2019 11:48
-
-
Save HaNdTriX/37cf6d69a01865364b971652c9ee173e to your computer and use it in GitHub Desktop.
React-Router hooks usage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useContext } from 'react' | |
import { __RouterContext as RouterContext, matchPath } from 'react-router-dom' | |
export default function useRouter (options = {}) { | |
const context = useContext(RouterContext) | |
const location = options.location || context.location | |
const match = options.path | |
? matchPath(location.pathname, options) | |
: context.match | |
return { ...context, location, match } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment