()
| 37 | }; |
| 38 | |
| 39 | export const useRouterMemory = (): UseRouterMemory => { |
| 40 | const [state, dispatch] = useReducer( |
| 41 | routerMemoryReducer, |
| 42 | undefined, |
| 43 | createRouterInitialState, |
| 44 | ); |
| 45 | |
| 46 | return { |
| 47 | ...state, |
| 48 | push: async (url, as) => { |
| 49 | // in memory router only supports url and as as strings, so we can convert |
| 50 | // them to URL objects for internal handling, this is compatible with next/router |
| 51 | const urlObject = new URL(url, 'http://localhost'); |
| 52 | const asObject = as ? new URL(as, 'http://localhost') : urlObject; |
| 53 | |
| 54 | dispatch({ |
| 55 | type: 'push', |
| 56 | payload: { |
| 57 | query: Object.fromEntries(urlObject.searchParams.entries()), |
| 58 | pathname: urlObject.pathname, |
| 59 | asPath: `${asObject.pathname}${ |
| 60 | asObject.search ? `?${asObject.search}` : '' |
| 61 | }`, |
| 62 | }, |
| 63 | }); |
| 64 | |
| 65 | return true; |
| 66 | }, |
| 67 | }; |
| 68 | }; |
nothing calls this directly
no outgoing calls
no test coverage detected