forked from remix-run/react-router
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuseRoutes.js
30 lines (26 loc) · 941 Bytes
/
useRoutes.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import useQueries from 'history/lib/useQueries'
import createTransitionManager from './createTransitionManager'
import warning from './routerWarning'
/**
* Returns a new createHistory function that may be used to create
* history objects that know about routing.
*
* Enhances history objects with the following methods:
*
* - listen((error, nextState) => {})
* - listenBeforeLeavingRoute(route, (nextLocation) => {})
* - match(location, (error, redirectLocation, nextState) => {})
* - isActive(pathname, query, indexOnly=false)
*/
function useRoutes(createHistory) {
warning(
false,
'`useRoutes` is deprecated. Please use `createTransitionManager` instead.'
)
return function ({ routes, ...options } = {}) {
const history = useQueries(createHistory)(options)
const transitionManager = createTransitionManager(history, routes)
return { ...history, ...transitionManager }
}
}
export default useRoutes