网站首页 > 博客文章 正文
路由采用的go-router路由框架:
final rootNavigatorKey = GlobalKey<NavigatorState>();
final GoRouter routerGlobal = GoRouter(
errorBuilder: (context, state) {
return const ErrorPage();
},
navigatorKey: rootNavigatorKey,
routes: <RouteBase>[
GoRoute(
path: '/',
name: "login",
parentNavigatorKey: rootNavigatorKey,
builder: (BuildContext context, GoRouterState state) {
return const LoginPage();
}),
//......省略部分路由
GoRoute(
path: '/error',
name: "error",
parentNavigatorKey: rootNavigatorKey,
builder: (BuildContext context, GoRouterState state) {
return const ErrorPage();
}),
],
);
首先在runApp(MyApp())前添加以下代码:
需要导入dart:html包,由于只能在web中使用,跨平台可以使用universal_html: ^1.2.1代替
if (kIsWeb) {
// 清空浏览器历史记录
html.window.history.replaceState(null, "", html.window.location.href);
// 禁止后退功能
html.window.onPopState.listen((event) {
html.window.history.pushState(null, "", html.window.location.href);
});
}
添加上面代码后,经过测试还是会后退一步,每当打开一个新的路由后需要再次调用下面代码:
GoRouter.of(context).go(menu.location!);
if (kIsWeb) {
html.window.history.replaceState(null, "", "#$location");
}
当点击浏览器后退按钮时,地址栏地址将不再发生变化:
- 上一篇: Flutter——按钮
- 下一篇: flutter软件开发笔记12-各功能组件讲解
猜你喜欢
- 2025-05-23 Flutter——路由
- 2025-05-23 flutter软件开发笔记18-线程管理
- 2025-05-23 Flutter TextField 边框样式以及提示文本
- 2025-05-23 Flutter缓存数据可以怎么做
- 2025-05-23 flutter软件开发笔记20-flutter web开发
- 2025-05-23 flutter软件开发笔记25-内置组件总结
- 2025-05-23 flutter软件开发笔记17-isolate的机制作用
- 2025-05-23 Flutter实战经验(十二):不同平台操作体验的差异和适配(一)
- 2025-05-23 Flutter GetX 硬核分享:Rx 扩展方法实践指南
- 2025-05-23 Flutter与Android iOS 的双向通信
你 发表评论:
欢迎- 380℃手把手教程「JavaWeb」优雅的SpringMvc+Mybatis整合之路
- 375℃用AI Agent治理微服务的复杂性问题|QCon
- 375℃IT全明星|IntelliJ IDEA学习笔记(四、idea中怎么创建maven项目)
- 366℃初次使用IntelliJ IDEA新建Maven项目
- 359℃Maven技术方案最全手册(mavena)
- 356℃安利Touch Bar 专属应用,让闲置的Touch Bar活跃起来!
- 354℃InfoQ 2024 年趋势报告:架构篇(infoq+2024+年趋势报告:架构篇分析)
- 353℃IntelliJ IDEA 2018版本和2022版本创建 Maven 项目对比
- 最近发表
- 标签列表
-
- powershellfor (55)
- messagesource (56)
- aspose.pdf破解版 (56)
- promise.race (63)
- 2019cad序列号和密钥激活码 (62)
- window.performance (66)
- qt删除文件夹 (72)
- mysqlcaching_sha2_password (64)
- ubuntu升级gcc (58)
- nacos启动失败 (64)
- ssh-add (70)
- jwt漏洞 (58)
- macos14下载 (58)
- yarnnode (62)
- abstractqueuedsynchronizer (64)
- source~/.bashrc没有那个文件或目录 (65)
- springboot整合activiti工作流 (70)
- jmeter插件下载 (61)
- 抓包分析 (60)
- idea创建mavenweb项目 (65)
- vue回到顶部 (57)
- qcombobox样式表 (68)
- vue数组concat (56)
- tomcatundertow (58)
- pastemac (61)
本文暂时没有评论,来添加一个吧(●'◡'●)