Open codegrue opened 4 years ago
This would build the widgets such as:
AdminLayout(child: DashboardPage());
I agree that sub-routes (or sub-routers) would be great. Not sure I agree with this though. The primary reason I like this idea is that it allows for logic to be shared across sub-routes. This is more similar to the way most web routers work (eg. express, Django) which share application logic.
An example for authentication:
sailor.addRoutes([
// '/admin', '/admin/dashboard', and '/admin/users' are all
// guarded against users who are not both logged in and an admin
SailorRoute(
name: "/admin",
builder: (context, args, params) => AdminLayout(),
routerGuards: [_isLoggedIn, _isAdmin],
subroutes: [
SailorRoute(
name: "/dashboard",
builder: (context, args, params) => DashboardPage(),
),
SailorRoute(
name: "/users",
builder: (context, args, params) => UsersPage(),
),
]
);
For a scenario where you have a master layout page that then contained child widgets, have a way to nest these to have deeper routes. For example:
Routes:
/admin/dashboard
/admin/users
This would build the widgets such as: