NyRouteGuard class
Base class for Nylo's RouteGuard.
Usage:
- Create a new class that extends RouteGuard. class AuthRouteGuard extends NyRouteGuard { AuthRouteGuard();
@override Future<PageRequest?> onRequest(PageRequest pageRequest) async {
// Check if user is authenticated
if (await Auth.loggedIn()) {
return redirect(HomePage.path);
}
return pageRequest;
} }
- Add the new RouteGuard to your route. appRouter() => nyRoutes((router) {
router.route(ProfilePage.path, (context) => ProfilePage(), routeGuards:
AuthRouteGuard() // new guard
);
});
- Inheritance
-
- Object
- RouteGuard
- NyRouteGuard
Constructors
Properties
- context → BuildContext?
-
The BuildContext for the current route.
no setter
- data → dynamic
-
The NyArgument passed from the last route.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- pageRequest ↔ PageRequest?
-
getter/setter pairinherited
-
queryParameters
→ Map<
String, String> ? -
The NyQueryParameters for the current route.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
addData(
dynamic currentData(dynamic data)) → dynamic - Add data to the current route.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
onRequest(
PageRequest pageRequest) → dynamic -
Called before a route is opened.
override
-
redirect(
dynamic path, {dynamic data, Map< String, dynamic> ? queryParameters, dynamic result, bool removeUntilPredicate(Route route)?, PageTransitionSettings? pageTransitionSettings, PageTransitionType? pageTransitionType, dynamic onPop(dynamic value)?}) → dynamic - Redirect to a new route.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited