I used flutter_modular for flutter web to navigation.
import 'package:flutter_modular/flutter_modular.dart';
class AppModule extends Module {
@override
final List<Bind> binds = [];
@override
final List<ModularRoute> routes = [
ChildRoute('/', child: (_, __) => HomeScreen()),
ChildRoute('/signin', child: (_, __) => SignInPage()),
ChildRoute('/login', child: (_, __) => LogInPage()),
ChildRoute('/404', child: (_, __) => Custome404()),
];
}
if unfortunately user typed URL like example.com/gfhgfhb/
.
The flutter modular plugin show error Error: RouteNotFoundException: Route (/rferwg) not found
. Now who can I set default 404 page in code?
CodePudding user response:
you can use WildcardRoute :
WildcardRoute(child: (context, args) => NotFoundPage()),
according to its documentation :
Have only one WildcardRoute per module and, if possible, let it be the last element.
CodePudding user response:
Do you use a MaterialApp
, CupertinoApp
, or WidgetsApp
somewhere ? If so, you could use the onUnknownRoute
property:
onUnknownRoute: (settings) {
return MaterialPageRoute(builder: (_) => PageNotFound());
},
https://medium.com/flutter/handling-404-page-not-found-error-in-flutter-731f5a9fba29