我想在我的 Flutter Web 应用程序中使用 GoRouter 创建一个工作流程而不更改 URL,但我无法做到这一点。即使使用 ShellRoute。我的路由器如下:
final GlobalKey<NavigatorState> _shellNavigatorKey =
GlobalKey<NavigatorState>();
final GlobalKey<NavigatorState> _rootNavigatorKey = GlobalKey<NavigatorState>();
final _router = GoRouter(navigatorKey: _rootNavigatorKey, routes: [
ShellRoute(
navigatorKey: _shellNavigatorKey,
builder: (context, state, child) {
return child;
},
routes: [
GoRoute(
path: '/',
parentNavigatorKey: _shellNavigatorKey,
builder: (context, state) => const ProcessesListPage(),
routes: [
GoRoute(
path: 'process',
parentNavigatorKey: _shellNavigatorKey,
pageBuilder: (context, state) => CustomTransitionPage(
key: state.pageKey,
child: const ProcessViewerPage(),
transitionsBuilder:
(context, animation, secondaryAnimation, child) =>
SlideTransition(
position: animation.drive(
Tween<Offset>(
begin: const Offset(1, 0),
end: Offset.zero,
).chain(CurveTween(curve: Curves.easeInOut)),
),
child: child),
),
),
],
),
],
)
]);
然后我使用
context.go("/process");
导航至流程路线
但这样做,网址从http://localhost:8000/
更改为http://localhost:8000/#/process
,而我想保留http://localhost:8000/
。我已经使用了 ShellRoute 和密钥,但我无法使其工作。
我也愿意接受不使用 GoRouter 来实现这一目标的解决方案。
我最终创建了自己的导航系统,没有 GoRouter 或任何路线,并使用事件系统来决定显示什么。我认为路由器必须与路由一起工作。我现在唯一的缺点是我错过了页面转换,但可以用动画来实现它们。