Flutter Modular redirect to 404 page

Issue

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.

Answered By – Hooman

Answer Checked By – Cary Denson (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *