flutter Auto_route 包不适用于 flutter 2.5.2 上的 Nestd 路由,我已将路由文件命名为与 router.dart 不同的名称,以防它弄乱默认路由设置,无法找到任何解决方案。
import 'package:auto_route/auto_route.dart';
import 'package:flutteraoutroutepackage/pages/pages.dart';
@MaterialAutoRouter(
replaceInRouteName: 'Page,Route',
routes: <AutoRoute>[
//HomePage route
AutoRoute(
path: '/',
page: HomePage,
initial: true,
children: [
//books route
AutoRoute(
path: "books",
name: "BooksRouter",
page: EmptyRouterPage,
children: [
AutoRoute(path: '', page: BooksPage),
AutoRoute(path: ':bookId', page: BookDetailsPage),
RedirectRoute(path: "*", redirectTo: '')
],
),
],
),
],
)
class $AppRouter {}
Run Code Online (Sandbox Code Playgroud)
主页
import 'package:flutter/material.dart';
import 'package:auto_route/auto_route.dart';
import 'package:flutteraoutroutepackage/routes/app_router.gr.dart';
class HomePage extends StatelessWidget {
const HomePage({Key? key}) : super(key: key); …Run Code Online (Sandbox Code Playgroud) flutter ×1