replace method

  1. @override
Future<Null> replace (
  1. dynamic path,
  2. [dynamic state]

Replace the current entry with a one (String or Location) on to the History list

You can optionally add a state object to add information about the entry that doesn't appear in the path.

This method will throw an ArgumentError if anything other than String or Location is given to it.


Future<Null> replace(dynamic path, [dynamic state]) async {
  // Validate arguments
  if (path is Location && path.state != null && state != null) {
        'WARNING: You should avoid adding the 2nd argument (state) when the 1st argument is a "Location" with a defined state; 2nd argument state will be ignored');

  // Compute next location and action
  Location nextLocation = (path is String)
      ? Location(pathname: path, state: state, key: _createKey())
      : Location.copy((path as Location),
          key: _createKey(), state: path.state ?? state);
  var nextAction = Action.replace;

  // Await Confirmation
  var ok = await _transitionManager.confirmTransitionTo(
      nextLocation, nextAction, _getConfirmation);
  if (!ok) {

  var href = _href(nextLocation);

  if (_domUtils.supportsHistory) {
    if (_transitionManager.listeningToWindowEvents) {
      _popMode = PopMode.force;
        {'key': nextLocation.key, 'state': nextLocation.state}, null, href);

    if (_forceRefresh) {
      _window.location.href = href;
    } else {
      var prevIndex = _allKeys.indexOf(_location.key);
      if (prevIndex != -1) {
        _allKeys[prevIndex] = location.key;
      _location = nextLocation;
      _action = nextAction;
  } else {
    if (state == null) {
          'WARNING: Browser history cannot push state in browsers that do not support HTML5 history');