首页 > 解决方案 > 暂存环境中的 RouteInformationParser.restoreRouteInformation 未更新浏览器 URL 栏

问题描述

我与我的团队一起开发 Flutter Web 应用程序,我正在尝试根据用户在我们应用程序中的页面更改浏览器 URL。

我已经设法在我的本地机器上完成这项工作,我们的应用程序的顶部看起来像这样:

final app = ChangeNotifierProvider<RouteModel>(
  create: (_) => RouteModel(
    visitStack: ListQueue.from([visit ?? PageVisit.home()]),
  ),
  child: Builder(builder: (BuildContext context) => MyApp()),
);
runApp(app);
class MyApp extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    final routeModel = context.watch<RouteModel>();
    final _routerDelegate = MyRouterDelegate(routeModel);
    final  _routeInformationParser = MyRouteInformationParser(routeModel);
    final _routeInformationProvider = MyRouteInformationProvider(routeModel);
    return MaterialApp.router(
      title: 'My App',
      routerDelegate: _routerDelegate,
      routeInformationParser: _routeInformationParser,
    );
  }
}

TheRouteModel是一个集线器,它接收来自页面的调用以导航到其他页面,并为内部应用程序状态处理 url、args 和其他帮助函数。

根据我对 Flutter 文档的了解, RouteInformationParser.restoreRouteInformation 应该在应用程序状态更改时更改浏览器 URL。如果向 MaterialApp.router 提供了 RouteInformationProvider,则其函数 routerReportsNewRouteInformation 可能会覆盖 RouteInformationParser.restoreRouteInformation。

浏览器 URL 在我们的本地计算机上按预期在导航时更改,但在我们的暂存环境中没有。

使用一些日志记录信息,我知道当我导航到新页面时,在本地机器和登台环境上都会调用以下函数:

如果我删除 RouteInformationProvider,我还可以删除 Router.navigate 调用,并且浏览器 URL 仍会在本地更新。

我的问题是:是否有特定的原因/配置可以使登台环境阻止浏览器 url 更改?

输出flutter --version

Flutter 1.23.0-18.1.pre • channel beta • https://github.com/flutter/flutter.git
Framework • revision 198df796aa (6 weeks ago) • 2020-10-15 12:04:33 -0700
Engine • revision 1d12d82d9c
Tools • Dart 2.11.0 (build 2.11.0-213.1.beta)

输出flutter doctor

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel beta, 1.23.0-18.1.pre, on Mac OS X 10.15.7 19H2 x86_64, locale fr-FR)

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
[✓] Xcode - develop for iOS and macOS (Xcode 11.7)
[✓] Chrome - develop for the web
[✓] Android Studio (version 3.5)
[✓] Connected device (2 available)

• No issues found!

标签: flutterurlflutter-web

解决方案


我刚刚遇到了类似的问题,发现我忘了实现RouterDelegate的currentConfiguration。这造成了不同。


推荐阅读