Mag*_*s W 5 dart flutter flutter-navigation
启动Flutter应用程序时出现以下错误:
??? EXCEPTION CAUGHT BY FLUTTER FRAMEWORK ??????????????????????????????????????????????????????????
The following message was thrown:
Could not navigate to initial route.
The requested route name was: "/animals/cats/lolcats"
The following routes were therefore attempted:
* /
* /animals
* /animals/cats
* /animals/cats/lolcats
This resulted in the following objects:
* MaterialPageRoute<dynamic>("/", animation: null)
* MaterialPageRoute<dynamic>("/animals", animation: null)
* null
* MaterialPageRoute<dynamic>("/animals/cats/lolcats", animation: null)
One or more of those objects was null, and therefore the initial route specified will be ignored and
"/" will be used instead.
????????????????????????????????????????????????????????????????????????????????????????????????????
Run Code Online (Sandbox Code Playgroud)
我已经宣布路线/animals/cats/lolcats:
'/animals': (context) => AnimalsScreen(context),
'/animals/dogs': (context) => DogsScreen(context),
'/animals/cats/lolcats': (context) => LolcatsScreen(context),
Run Code Online (Sandbox Code Playgroud)
并将我设置initialRoute为
initialRoute: '/animals/cats/lolcats',
Run Code Online (Sandbox Code Playgroud)
即使声明了路由,为什么仍然出现上述错误?
我认为错误日志非常明确。
由于您使用“/”来划分路线,因此它被解释为“子路线”。实际上,它正试图一条接一条地通过这些路线:
* /
* /animals
* /animals/cats
* /animals/cats/lolcats
Run Code Online (Sandbox Code Playgroud)
由于/animals/cats未定义,t 收到错误,然后返回初始路线:/
如果你想解决这个问题,像这样用下划线重命名你的路线:
/animals_cats_lolcats
所以它不会尝试获取/animals/cats不存在的
| 归档时间: |
|
| 查看次数: |
846 次 |
| 最近记录: |