+1
-1
| { | ||
| "name": "wouter", | ||
| "version": "3.9.0", | ||
| "version": "3.10.0", | ||
| "description": "Minimalist-friendly ~1.5KB router for React", | ||
@@ -5,0 +5,0 @@ "type": "module", |
+4
-1
@@ -234,3 +234,6 @@ import { parse as parsePattern } from "regexparam"; | ||
| ); | ||
| navigate(location + "?" + tempSearchParams, options); | ||
| navigate( | ||
| location + (tempSearchParams.size ? "?" + tempSearchParams : ""), | ||
| options | ||
| ); | ||
| }); | ||
@@ -237,0 +240,0 @@ |
@@ -11,2 +11,3 @@ import mitt from "mitt"; | ||
| searchPath = "", | ||
| state = null, | ||
| static: staticLocation, | ||
@@ -16,2 +17,3 @@ record, | ||
| let initialPath = path; | ||
| const initialState = state; | ||
| if (searchPath) { | ||
@@ -24,6 +26,7 @@ // join with & if path contains search query, and ? otherwise | ||
| let [currentPath, currentSearch = ""] = initialPath.split("?"); | ||
| let currentState = initialState; | ||
| const history = [initialPath]; | ||
| const emitter = mitt(); | ||
| const navigateImplementation = (path, { replace = false } = {}) => { | ||
| const navigateImplementation = (path, { replace = false, state } = {}) => { | ||
| if (record) { | ||
@@ -38,2 +41,3 @@ if (replace) { | ||
| [currentPath, currentSearch = ""] = path.split("?"); | ||
| if (state !== undefined) currentState = state; | ||
| emitter.emit("navigate", path); | ||
@@ -63,7 +67,6 @@ }; | ||
| history.splice(0, history.length); | ||
| navigateImplementation(initialPath); | ||
| navigateImplementation(initialPath, { state: initialState }); | ||
| } | ||
| return { | ||
| const memoryLocationResult = { | ||
| hook: useMemoryLocation, | ||
@@ -75,2 +78,9 @@ searchHook: useMemoryQuery, | ||
| }; | ||
| Object.defineProperty(memoryLocationResult, "state", { | ||
| enumerable: true, | ||
| get: () => currentState, | ||
| }); | ||
| return memoryLocationResult; | ||
| }; |
@@ -13,20 +13,23 @@ import { | ||
| type HookReturnValue = { | ||
| type HookReturnValue<S = unknown> = { | ||
| hook: BaseLocationHook; | ||
| searchHook: BaseSearchHook; | ||
| navigate: Navigate; | ||
| navigate: Navigate<S>; | ||
| readonly state: S | null; | ||
| }; | ||
| type StubHistory = { history: Path[]; reset: () => void }; | ||
| export function memoryLocation(options?: { | ||
| export function memoryLocation<S = unknown>(options?: { | ||
| path?: Path; | ||
| searchPath?: SearchString; | ||
| state?: S; | ||
| static?: boolean; | ||
| record?: false; | ||
| }): HookReturnValue; | ||
| export function memoryLocation(options?: { | ||
| }): HookReturnValue<S>; | ||
| export function memoryLocation<S = unknown>(options?: { | ||
| path?: Path; | ||
| searchPath?: SearchString; | ||
| state?: S; | ||
| static?: boolean; | ||
| record: true; | ||
| }): HookReturnValue & StubHistory; | ||
| }): HookReturnValue<S> & StubHistory; |
75331
0.65%930
1.64%