didPushRouteInformation method

  1. @override
Future<bool> didPushRouteInformation(
  1. RouteInformation routeInformation
)
override

浏览器的地址栏和本地的地址可能不相等; 本地地址没有使用 Uri 编码,即使使用也可能出问题, 如:' '有两种形式 '+'和'%2B',所以RouteInformation.uri不会被使用

RouteInformation.state获取stateEntry

Implementation

@override
Future<bool> didPushRouteInformation(RouteInformation routeInformation) {
  if (!delegate.updateLocation) return SynchronousFuture(false);

  final state = routeInformation.state;
  final stateEntry = RouteQueue.getLast(state, delegate);

  assert(Log.e('uri: ${routeInformation.uri}'));

  final pre = routeQueue.pre;
  if (stateEntry != null && stateEntry.eq(pre)) {
    // assert(Log.i('pre:'));
    // assert(Log.w(pre?.toJson(detail: true).logPretty()));
    // assert(Log.i('state:'));
    // assert(Log.w(stateEntry.toJson(detail: true).logPretty()));
    assert(!routeQueue.isSingle);
    routeQueue._current?._removeCurrent(update: false);
  } else {
    RouteQueueEntry? entry = stateEntry;

    if (entry == null) {
      final uri = routeInformation.uri;

      final realParams = <String, dynamic>{};

      final route =
          delegate.rootPage.getPageFromLocation(uri.path, realParams);
      if (route == null) {
        return SynchronousFuture(false);
      }

      final pageKey = delegate.newPageKey(prefix: 'p+');
      entry = RouteQueueEntry(
        params: realParams,
        nPage: route,
        queryParams: uri.queryParameters,
        pageKey: pageKey,
      );
    }

    routeQueue.insert(entry, update: false);
  }
  return SynchronousFuture(true);
}