Skip to content

Commit 47dafd7

Browse files
krituaolegman
authored andcommitted
Fix for force routing to current page (#4)
* Fix for force routing to current page * Fix for force routing to current page * Fix for force routing to current page
1 parent c88c123 commit 47dafd7

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-router-async",
3-
"version": "0.7.3",
3+
"version": "0.7.4",
44
"author": {
55
"name": "Oleg Martynov",
66
"email": "[email protected]"

src/browser-router.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ export default class BrowserRouter extends Router {
3030
Router: BrowserRouter
3131
};
3232
}
33-
async navigate(path, state = {}, ctx = new Context()) {
33+
async navigate(path, state = {}, ctx = new Context(), force = false) {
3434
const currentPath = window.location.pathname + window.location.search;
3535

36-
if(path !== currentPath) {
36+
if(force || path !== currentPath) {
3737
// if (this.router.isRunning) this.router.cancel(false);
3838
const { redirect, error } = await this.router.resolve({ path, state, ctx });
3939
if (!(error && error.message === 'Cancelled')) {
@@ -46,14 +46,14 @@ export default class BrowserRouter extends Router {
4646
}
4747
}
4848
}
49-
async push(path, state = {}, ctx = new Context()) {
49+
async push(path, state = {}, ctx = new Context(), force = false) {
5050
// console.warn('Please use navigate method instead of push, it will be deprecated in future');
5151
if (typeof path === 'string') {
52-
await this.navigate(path, state, ctx);
52+
await this.navigate(path, state, ctx, force);
5353
} else {
5454
let fullPath = path.pathname;
5555
if (path.query) fullPath += `?${stringifyQuery(path.query)}`;
56-
await this.navigate(fullPath, state, ctx);
56+
await this.navigate(fullPath, state, ctx, force);
5757
}
5858
}
5959
// TODO: maybe we need to make this history methods works through navigate?

0 commit comments

Comments
 (0)