Skip to content

Commit

Permalink
Merge pull request #217 from augustomallmann/router-back-reload
Browse files Browse the repository at this point in the history
feat: navigate back in history and reload current URL
  • Loading branch information
tj-kev committed Feb 17, 2022
2 parents 194d674 + 9c89eeb commit ed51679
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docs/flareact-router.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,11 @@ export default function Index() {

// Navigate to the dynamic route /posts/[slug] using `href`, `as`
router.push("/posts/[slug]", "/posts/my-first-post");

// Navigate back in history
router.back();

// Reload the current URL
router.reload();
}
```
12 changes: 12 additions & 0 deletions src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,16 @@ export function RouterProvider({
window.history.pushState({ href, asPath }, null, asPath);
}

// Navigate back in history
function back() {
window.history.back()
}

// Reload the current URL
function reload() {
window.location.reload()
}

function prefetch(href, as, { priority } = {}) {
if (process.env.NODE_ENV !== "production") {
return;
Expand Down Expand Up @@ -195,6 +205,8 @@ export function RouterProvider({
pathname: route.href,
asPath: route.asPath,
push,
back,
reload,
prefetch,
query,
};
Expand Down

0 comments on commit ed51679

Please sign in to comment.