有些页面需要保持单例,比如:历史 -> 详情 -> 历史-> 详情,在返回的时候需要多次返回历史页面和详情页面,期望的场景是历史页面和详情页面都是单例,假如一个用户的路径是:
替换 Router 实现,比如 AutoRoute 不太现实,有太多页面了,测试工作量很大。
GoRouter 本身只支持push
, pushReplacement
, go
, replace
, pop
。
RouteMatchList _updateRouteMatchList( RouteMatchList newMatchList, { required RouteMatchList? baseRouteMatchList, required Completer<Object?>? completer, required NavigatingType type, }) { switch (type) { case NavigatingType.push: return baseRouteMatchList!.push( ImperativeRouteMatch( pageKey: _getUniqueValueKey(), completer: completer!, matches: newMatchList, ), ); case NavigatingType.pushReplacement: final RouteMatch routeMatch = baseRouteMatchList!.last; return baseRouteMatchList.remove(routeMatch).push( ImperativeRouteMatch( pageKey: _getUniqueValueKey(), completer: completer!, matches: newMatchList, ), ); case NavigatingType.replace: final RouteMatch routeMatch = baseRouteMatchList!.last; return baseRouteMatchList.remove(routeMatch).push( ImperativeRouteMatch( pageKey: routeMatch.pageKey, completer: completer!, matches: newMatchList, ), ); case NavigatingType.go: return newMatchList; case NavigatingType.restore: // Still need to consider redirection. return baseRouteMatchList!.uri.toString() != newMatchList.uri.toString() ? newMatchList : baseRouteMatchList; } }