Search code examples
flutterflutter-webflutter-navigationflutter-plugin

Flutter Modular redirect to 404 page


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?


Solution

  • 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.