diff --git a/packages/react-router/src/ReactRouter/Router.tsx b/packages/react-router/src/ReactRouter/Router.tsx index d6b735e435..863619bb2d 100644 --- a/packages/react-router/src/ReactRouter/Router.tsx +++ b/packages/react-router/src/ReactRouter/Router.tsx @@ -22,7 +22,7 @@ class RouteManager extends React.Component v.prevId === view.id); viewsToRemove.forEach(v => { // Don't remove if view is currently active @@ -339,15 +349,20 @@ class RouteManager extends React.Component x.pathname.toLowerCase() === url.toLowerCase()); - return last; + pop() { + this.locationHistory.pop(); + } + + replace(location: HistoryLocation) { + this.locationHistory.pop(); + this.locationHistory.push(location); + } + + findLastLocationByUrl(url: string) { + for (let i = this.locationHistory.length - 1; i >= 0; i--) { + const location = this.locationHistory[i]; + if (location.pathname.toLocaleLowerCase() === url.toLocaleLowerCase()) { + return location; + } + } + return undefined; + } + + previous() { + return this.locationHistory[this.locationHistory.length - 2]; + } + + current() { + return this.locationHistory[this.locationHistory.length - 1]; } }