Skip to content

Commit

Permalink
feat: move updating browser history into separate function
Browse files Browse the repository at this point in the history
This allows to inherit from this class and overload this logic. For example:
It adds the possibility to use angulars $location service instead of the
history api directly.
  • Loading branch information
micha149 committed Oct 12, 2015
1 parent 0ee6ce6 commit f758912
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions modules/router5.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class Router5 {
this.navigate(opts.defaultRoute, opts.defaultParams, {reload: true, replace: true})
}
} else {
browser[newState ? 'pushState' : 'replaceState'](toState, '', this.buildUrl(toState.name, toState.params))
this.updateBrowserState(toState, this.buildUrl(toState.name, toState.params), newState)
}
})
}
Expand Down Expand Up @@ -604,10 +604,21 @@ class Router5 {
return
}

browser[opts.replace ? 'replaceState' : 'pushState'](this.lastStateAttempt, '', url)
this.updateBrowserState(this.lastStateAttempt, url, opts.replace)
if (done) done(null, state)
})
}

/**
* Update the browser history
* @param {Object} stateObject State object to be used
* @param {string} url Absolute url to be used
* @param {boolean} [replace=false] If replaceState or pushState should be used
* @param {string} [title=''] The title to be used for history
*/
updateBrowserState(stateObject, url, replace = false, title = '') {
browser[replace ? 'replaceState' : 'pushState'](stateObject, title, url);
}
}

export default Router5

0 comments on commit f758912

Please sign in to comment.