The GoRouterState object has an error property which I would expect to hold a GoException when I open a non-existing route. Currently this exception is only available in errorBuilder and errorPageBuilder, but always null in onException and redirect.
My use case would be: I try to protect most of the screens with authentication by the redirect callback, but I can't make error screens unprotected as state.error is always null and nothing else indicates that I am on an error screen. Only buildError receives the error, but that is too late as redirect will redirect back the user before that. This can be easily triggered by deep links sadly.
To reproduce please run my attached code sample. As onException and errorBuilder are mutually exclusive, one of them is commented out.
I'm using go_router: 14.4.1 with flutter 3.24.4 on Android (but I don't think it is platform dependant, however I don't know and care about web or any non-mobile).
Expected results
The GoRouterState's error property should be non-null when the matched location is not registered among the possible routes. In the example code all errors should be like the following after tapping the Open a non-existing route button:
/404: GoException: no routes for lcoation: /404
Actual results
The GoRouterState's error property is null when opening a non-existing route. In the example app all errors are like this:
Doctor output
```console
[✓] Flutter (Channel stable, 3.24.4, on macOS 15.1 24B83 darwin-arm64, locale en-HU)
• Flutter version 3.24.4 on channel stable at /Users/macbookpro/devtools/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 603104015d (3 weeks ago), 2024-10-24 08:01:25 -0700
• Engine revision db49896cf2
• Dart version 3.5.4
• DevTools version 2.37.3
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
• Android SDK at /Users/macbookpro/devtools/android_sdk
• Platform android-34, build-tools 34.0.0
• ANDROID_SDK_ROOT = /Users/macbookpro/devtools/android_sdk
• Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 21.0.3+-79915917-b509.11)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 16.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 16B40
• CocoaPods version 1.16.1
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2024.2)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 21.0.3+-79915917-b509.11)
[✓] VS Code (version 1.95.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.100.0
[✓] Connected device (4 available)
• SM S906U1 (mobile) • RFCT20EQM0M • android-arm64 • Android 14 (API 34)
• macOS (desktop) • macos • darwin-arm64 • macOS 15.1 24B83 darwin-arm64
• Mac Designed for iPad (desktop) • mac-designed-for-ipad • darwin • macOS 15.1 24B83 darwin-arm64
• Chrome (web) • chrome • web-javascript • Google Chrome 130.0.6723.117
! Error: Browsing on the local area network for László’s iPhone. Ensure the device is unlocked and attached with a cable or associated with the same local area network as this Mac.
The device must be opted into Developer Mode to connect wirelessly. (code -27)
[✓] Network resources
• All expected network resources are available.
• No issues found!
```
Steps to reproduce
The
GoRouterState
object has anerror
property which I would expect to hold aGoException
when I open a non-existing route. Currently this exception is only available inerrorBuilder
anderrorPageBuilder
, but alwaysnull
inonException
andredirect
.My use case would be: I try to protect most of the screens with authentication by the
redirect
callback, but I can't make error screens unprotected asstate.error
is alwaysnull
and nothing else indicates that I am on an error screen. OnlybuildError
receives the error, but that is too late asredirect
will redirect back the user before that. This can be easily triggered by deep links sadly.To reproduce please run my attached code sample. As
onException
anderrorBuilder
are mutually exclusive, one of them is commented out.I'm using
go_router
:14.4.1
with flutter3.24.4
on Android (but I don't think it is platform dependant, however I don't know and care about web or any non-mobile).Expected results
The
GoRouterState
'serror
property should be non-null when the matched location is not registered among the possible routes. In the example code all errors should be like the following after tapping theOpen a non-existing route
button:Actual results
The
GoRouterState
'serror
property isnull
when opening a non-existing route. In the example app all errors are like this:Code sample
Code sample
```dart import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; void main() => runApp(const MyApp()); final _errorNotifier = ValueNotifierScreenshots or Video
No response
Logs
No response
Flutter Doctor output
Doctor output
```console [✓] Flutter (Channel stable, 3.24.4, on macOS 15.1 24B83 darwin-arm64, locale en-HU) • Flutter version 3.24.4 on channel stable at /Users/macbookpro/devtools/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 603104015d (3 weeks ago), 2024-10-24 08:01:25 -0700 • Engine revision db49896cf2 • Dart version 3.5.4 • DevTools version 2.37.3 [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0) • Android SDK at /Users/macbookpro/devtools/android_sdk • Platform android-34, build-tools 34.0.0 • ANDROID_SDK_ROOT = /Users/macbookpro/devtools/android_sdk • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 21.0.3+-79915917-b509.11) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 16.1) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 16B40 • CocoaPods version 1.16.1 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 2024.2) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 21.0.3+-79915917-b509.11) [✓] VS Code (version 1.95.2) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.100.0 [✓] Connected device (4 available) • SM S906U1 (mobile) • RFCT20EQM0M • android-arm64 • Android 14 (API 34) • macOS (desktop) • macos • darwin-arm64 • macOS 15.1 24B83 darwin-arm64 • Mac Designed for iPad (desktop) • mac-designed-for-ipad • darwin • macOS 15.1 24B83 darwin-arm64 • Chrome (web) • chrome • web-javascript • Google Chrome 130.0.6723.117 ! Error: Browsing on the local area network for László’s iPhone. Ensure the device is unlocked and attached with a cable or associated with the same local area network as this Mac. The device must be opted into Developer Mode to connect wirelessly. (code -27) [✓] Network resources • All expected network resources are available. • No issues found! ```