我正在使用Flutter构建一个简单的Web应用程序。导航使用go_router完成。
static final routerConfig = GoRouter(
routes: [
GoRoute(
path: Routes.login,
builder: (context, state) => const LoginPage(),
),
GoRoute(
path: Routes.loginSuccess,
builder: (context, state) {
var code = state.queryParameters['code'];
var stateParam = state.queryParameters['state'];
return const LoginPage();
},
),
],
initialLocation: Routes.login,
);
这些路线是:
class Routes {
static const login = '/';
static const loginSuccess = '/login-success';
}
然而,当Amplify以code
和state
作为查询参数返回到我的回调函数时,我得到了以下错误。
======== Exception caught by Flutter framework =====================================================
The following message was thrown:
Could not navigate to initial route.
The requested route name was: "/login-success?code=hiddenCode&state=hiddenState"
There was no corresponding route in the app, and therefore the initial route specified will be ignored and "/" will be used instead.
====================================================================================================
路由通过
context.go(Uri(
path: Routes.loginSuccess,
queryParameters: {'code': 'myCode', 'state': 'myState'}).toString());
只是工作。
如果通过身份验证提供程序重新启动应用程序,我会得到错误。
有什么不对的?
1条答案
按热度按时间qnyhuwrf1#
找到问题所在了。这是由FutureBuilder引起的,它最初返回一个空的MaterialApp小部件,没有任何路由。因此,请确保您的路由器在启动时已设置。