gurleensethi / sailor

Easy page navigation and management in Flutter apps.
https://pub.dev/packages/sailor
MIT License
145 stars 24 forks source link

Feature: Nested Pages #43

Open codegrue opened 4 years ago

codegrue commented 4 years ago

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:

sailor.addRoutes([
  SailorRoute(
    name: "/admin",
    builder: (context, args, params) => AdminLayout(),
    subroutes: [
      SailorRoute(
        name: "/dashboard",
        builder: (context, args, params) => DashboardPage(),
      ),
      SailorRoute(
        name: "/users",
        builder: (context, args, params) => UsersPage(),
      ),   
    ]   
);

This would build the widgets such as:

AdminLayout(child: DashboardPage());
alexandradeas commented 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(),
      ),   
    ]   
);