Skip to content

Commit

Permalink
Add useLocation check
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Nov 26, 2024
1 parent 26f830d commit a5d9759
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/router/src/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ function getLocationWithQuery() {
}

export function useLocation() {
return useContext( RoutesContext );
const context = useContext( RoutesContext );
if ( ! context ) {
throw new Error( 'useLocation must be used within a RouterProvider' );
}
return context;
}

export function useHistory() {
Expand Down

0 comments on commit a5d9759

Please sign in to comment.