RoutePath compare by value
I have a component routed by 2 different RoutePath objects. I want to check which route is used in onActivate with code like this:
@override
void onActivate(RouterState previous, RouterState current) {
if (current.routePath == RoutePaths.a) {
// Do something
} else if (current.routePath == RoutePaths.b) {
// Do something else
}
}
This doesn't work because the current instance is different to RoutePaths.a (for example) and RoutePath does not implement the equality operator.
RoutePath used to implement operator == to support such comparisons, but it was removed in favor of better tree-shaking since it wasn't widely used. The issue with operator == is that once you use a == comparison elsewhere in your app, all implementations are retained in the release build (even if they're never used by a == comparison).
We may reevaluate this again, but for now you could just compare the URL values:
if (current.routePath.toUrl() == RoutePaths.a.toUrl()) {
...
}
Makes sense. Maybe a good argument for language support of value types? Anyway feel free to close the ticket if you don't need it.