Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ Returns an object with the following properties:
- `path: string` - The current path
- `query: Record<string, string>` - The current query string parameters (`/profile?name=John` -> `{ name: 'John' }`)
- `route: (url: string, replace?: boolean) => void` - A function to programmatically navigate to a new route. The `replace` param can optionally be used to overwrite history, navigating them away without keeping the current location in the history stack.
- `back: () => void` - A function to programmatically navigate back one entry in the browser history stack.

### `useRoute`

Expand Down
1 change: 1 addition & 0 deletions src/router.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ interface LocationHook {
path: string;
query: Record<string, string>;
route: (url: string, replace?: boolean) => void;
back: () => void;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also offer .forward() at the same time for balance?

}
export const useLocation: () => LocationHook;

Expand Down
4 changes: 4 additions & 0 deletions src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ function handleNav(state, action) {

if (push === true) history.pushState(null, '', url);
else if (push === false) history.replaceState(null, '', url);

return url;
};

Expand Down Expand Up @@ -112,6 +113,9 @@ export function LocationProvider(props) {
path,
query: Object.fromEntries(u.searchParams),
route: (url, replace) => route({ url, replace }),
back: () => {
Copy link
Copy Markdown
Member Author

@JoviDeCroock JoviDeCroock Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

canGoBack or get canGoBack could rely on history.length being > 1 if we also want to support that API surface

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see too much of a need personally, though wouldn't hurt if added either

history.back();
},
wasPush
};
}, [url]);
Expand Down
Loading