routerReportsNewRouteInformation method
- RouteInformation routeInformation, {
- RouteInformationReportingType type = RouteInformationReportingType.none,
A callback called when the Router widget reports new route information
The subclasses can override this method to update theirs values or trigger other side effects. For example, the PlatformRouteInformationProvider overrides this method to report the route information back to the engine.
The routeInformation
is the new route information generated by the
Router rebuild, and it can be the same or different from the
value.
The type
denotes the Router's intention when it reports this
routeInformation
. It is useful when deciding how to update the internal
state of RouteInformationProvider subclass with the routeInformation
.
For example, PlatformRouteInformationProvider uses this property to
decide whether to push or replace the browser history entry with the new
routeInformation
.
For more information on how Router determines a navigation event, see the "URL updates for web applications" section in the Router documentation.
Implementation
@override
void routerReportsNewRouteInformation(RouteInformation routeInformation,
{RouteInformationReportingType type =
RouteInformationReportingType.none}) {
// GoRouteInformationParser should always report encoded route match list
// in the state.
assert(routeInformation.state != null);
final bool replace;
switch (type) {
case RouteInformationReportingType.none:
if (!_valueHasChanged(
newLocationUri: routeInformation.uri,
newState: routeInformation.state)) {
return;
}
replace = _valueInEngine == _kEmptyRouteInformation;
case RouteInformationReportingType.neglect:
replace = true;
case RouteInformationReportingType.navigate:
replace = false;
}
SystemNavigator.selectMultiEntryHistory();
SystemNavigator.routeInformationUpdated(
uri: routeInformation.uri,
state: routeInformation.state,
replace: _routerNeglect || replace,
);
_value = _valueInEngine = routeInformation;
}