Flutter GoException路由匹配失败:Firebase Auth跳转无对应路由
遇到错误:
GoException: no routes for location: com.googleusercontent.apps.1052157635-94tcrdep4q1r9g3gvi5dvllrejmali://firebaseauth/link?deep_link_id=https%3A%2F%2Ftonns-a06e3.firebaseapp.com%2F__%2Fauth%2Fcallback%3FauthType%3DsignInWithRedirect%26link%3Dhttps%253A%252F%252Ftonns-a06e3.firebaseapp.com%252F__%252Fauth%252Fhandler%253Fstate%253DAMbdmDlHduq-oYEjfP-Iey_XlGlyF61HK5tRsirFPGToxun0b165nOXoI51r9kzyUqaKTEpMiVtopoFLf6Ew6EvqJq0_VB4WY4_gxGLf4aRdLZ__KyW5S9FAY2l3bprsJwRe1iZXcZRxuBWLHNoMBw8Iu_P5mrsdxwXACiggwXTDEqagN5LDQ1ucxGs0SFJ4H4nHOmxmhHv0GrQrcDASHXhJZq3hJRLWAouW2Rn7Pq9nf-XOPsZ9R7nqOicBYG5go1BxAtvqBr_BbcEdbpvb_iprWGYL-RP0h9UdYeHYEhG6WhA1veuzBq0d3lirXYzbumylCyW4mTzJzdvIn9RR0TBF8mcyN_6WYvgLZhAt96b2UxG0Z4_6lw%2526code%253D4%25252F0AeanS0YosOSB-cJCOyK9e7ttvob8I1stlJRbqo7leg_5gK2FqtSZ2Sjn9v-rriDL7mnrYQ%2526scope%253Demail%252520openid%252520https%25253A%25252F%25252Fwww.googleapis.com%25252Fauth%25252Fuserinfo.email%2526authuser%253D0%2526prompt%253Dnone%26eventId%3DTYKPLUZAAI.
当前GoRouter配置:
GoRoute( path: '/firebaseauth/link', builder: (BuildContext context, GoRouterState state) { debugPrint('Firebase Auth Link'); final queryParams = state.uri.queryParameters; if (queryParams.containsKey('error')) { return const ErrorPage(); } else { return AuthWall( buildSuccessScreen: (_) { return Container(); }, screenTitle: StringConfig.login.title, screenDescription: StringConfig.login.screenDescription, ); } }, ),
info.plist配置:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>CADisableMinimumFrameDurationOnPhone</key> <true/> <key>CFBundleDevelopmentRegion</key> <string>$(DEVELOPMENT_LANGUAGE)</string> <key>CFBundleDisplayName</key> <string>tonns</string> <key>CFBundleExecutable</key> <string>$(EXECUTABLE_NAME)</string> <key>CFBundleIdentifier</key> <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string> <key>CFBundleInfoDictionaryVersion</key> <string>6.0</string> <key>CFBundleName</key> <string>XXXX</string> <key>CFBundlePackageType</key> <string>APPL</string> <key>CFBundleShortVersionString</key> <string>$(FLUTTER_BUILD_NAME)</string> <key>CFBundleSignature</key> <string>????</string> <key>CFBundleVersion</key> <string>$(FLUTTER_BUILD_NUMBER)</string> <key>FlutterDeepLinkingEnabled</key> <true/> <key>LSRequiresIPhoneOS</key> <true/> <key>NSCameraUsageDescription</key> <string>We need access to your camera to take photos and videos.</string> <key>NSLocationAlwaysAndWhenInUseUsageDescription</key> <string>We need your location to provide better services both in the foreground and background.</string> <key>NSLocationAlwaysUsageDescription</key> <string>We need your location to provide better services even when the app is in the background.</string> <key>NSLocationWhenInUseUsageDescription</key> <string>We need your location to provide better services.</string> <key>NSMicrophoneUsageDescription</key> <string>We need access to your microphone to record audio during sessions.</string> <key>NSPhotoLibraryAddUsageDescription</key> <string>We need access to your photo library to save photos.</string> <key>NSPhotoLibraryUsageDescription</key> <string>We need access to your photo library to save and access photos.</string> <key>NSUserNotificationAlertStyle</key> <string>Alert</string> <key>UIApplicationSupportsIndirectInputEvents</key> <true/> <key>UIBackgroundModes</key> <array> <string>fetch</string> <string>location</string> <string>remote-notification</string> </array> <key>UILaunchStoryboardName</key> <string>LaunchScreen</string> <key>UIMainStoryboardFile</key> <string>Main</string> <key>UISupportedInterfaceOrientations</key> <array> <string>UIInterfaceOrientationPortrait</string> <string>UIInterfaceOrientationLandscapeLeft</string> <string>UIInterfaceOrientationLandscapeRight</string> </array> <key>UISupportedInterfaceOrientations~ipad</key> <array> <string>UIInterfaceOrientationPortrait</string> <string>UIInterfaceOrientationPortraitUpsideDown</string> <string>UIInterfaceOrientationLandscapeLeft</string> <string>UIInterfaceOrientationLandscapeRight</string> </array> <!-- Add the custom URL scheme --> <key>CFBundleURLTypes</key> <array> <dict> <key>CFBundleTypeRole</key> <string>Editor</string> <key>CFBundleURLSchemes</key> <array> <string>com.googleusercontent.apps.105XXX3657635-94tcrdep4q1r9g3gvi8b5dvllrejmali</string> </array> </dict> </array> </dict> </plist>
请问我的GoRouter定义是否正确?是否需要修改?
你的GoRouter配置存在问题,需要调整,同时还有一处关键配置不一致:
先修复URL Scheme不一致问题
错误中的链接scheme是com.googleusercontent.apps.1052157635-94tcrdep4q1r9g3gvi5dvllrejmali,但info.plist里配置的是com.googleusercontent.apps.105XXX3657635-94tcrdep4q1r9g3gvi8b5dvllrejmali,两者不匹配会导致系统无法将链接路由到你的应用,必须先把info.plist里的scheme改成和错误中的完全一致。调整GoRouter路由配置
原路由路径本身没问题,但需要确保GoRouter能正确处理自定义scheme的深层链接,建议做以下优化:GoRoute( path: '/firebaseauth/link', name: 'firebase-auth-link', // 命名路由,方便跳转和匹配 builder: (BuildContext context, GoRouterState state) { debugPrint('Firebase Auth Link: ${state.uri}'); final queryParams = state.uri.queryParameters; // 解析deep_link_id参数,这里可以补充Firebase Auth的回调处理逻辑 final deepLinkId = queryParams['deep_link_id']; if (deepLinkId != null) { // 比如调用Firebase Auth的signInWithCredential完成登录流程 } if (queryParams.containsKey('error')) { return const ErrorPage(); } else { return AuthWall( buildSuccessScreen: (_) { return Container(); }, screenTitle: StringConfig.login.title, screenDescription: StringConfig.login.screenDescription, ); } }, ),同时在GoRouter初始化时开启调试日志,方便排查问题:
final GoRouter _router = GoRouter( initialLocation: '/', routes: [ // 其他路由... GoRoute( path: '/firebaseauth/link', name: 'firebase-auth-link', builder: ..., ), ], debugLogDiagnostics: true, // 开启路由调试日志 );额外检查项
- 确认Firebase控制台中配置的回调URL和应用bundle ID、自定义scheme完全匹配
- 执行
flutter clean和flutter pub get后重新编译应用,避免配置缓存问题 - iOS测试深层链接时,建议重启应用或通过Xcode重新安装后测试
内容的提问来源于stack exchange,提问作者MattPrash

