【发布时间】:2021-01-21 23:21:12
【问题描述】:
我在 Flutter Web 应用程序中使用命名路由进行导航。导航到所需路由时,URL 会更新,但我无法通过 URL 栏直接导航到路由。每次我尝试在 URL 中添加路径时,都会将我带到“.../#/”
使用更新的 URL 执行热重载时,我收到以下错误:
Could not navigate to initial route.
The requested route name was: "/Page_One"
There was no corresponding route in the app, and therefore the initial route specified will be ignored and "/" will be used instead.
class Start extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'My Site',
theme: ThemeData(...),
initialRoute: '/',
routes: <String, WidgetBuilder> {
"/": (context) => MainPage(),
"/Page_One": (context) => Page2(0),
"/Page_Two": (context) => Page2(1),
"/Page_Three": (context) => Page2(2),
},
);
}
}
编辑:我也用onGenerateRoute 尝试过这个,但没有运气。
EDIT2:我在生产 URL 和 localhost 上都调用它们(例如http://localhost:12345/#/Page_Two。不,localhost:12345/Page_Two 和 localhost:12345/#Page_Two 也不起作用。
Edit3:我打电话给runApp void main() => runApp(new MaterialApp(home: Start()));
【问题讨论】:
-
这似乎是针对子路由的,虽然有用但不幸的是并没有解决这个问题。
-
能否添加网址以及如何称呼
runApp? -
你在应用程序中使用什么方法来改变路由?
-
@creativecreatorormaybenot 我将信息作为编辑添加到主帖子中。 @YouriLieverdink 我正在使用
Navigator.pushNamed在应用程序中导航。那工作正常。当我转到.../#/Page_Two时,我只想能够导航到Page2(1)
标签: flutter routes flutter-web