flutterflutter-go-router

Error "GoException: no routes for location"


In simulator I am getting the error message when running the code below:

"GoException: no routes for location: https://www.[testurl].com/jobs/testjobtitle

Please can you tell me why the simulator isn't displaying a blank page with the title "Jobs" as per this line?:

appBar: AppBar(title: const Text('Jobs')),

This is the test code:

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);

  runApp(MaterialApp.router(routerConfig: router));
}


final router = GoRouter(
  routes: [
    GoRoute(
      path: '/',
      builder: (_, __) => Scaffold(
        appBar: AppBar(title: const Text('Home Screen')),
      ),
      routes: [
        GoRoute(
          path: 'jobs/*',
          // builder: (_, state) => ItemDetails(path: state.path),
          builder: (_, __) => Scaffold(
            appBar: AppBar(title: const Text('Jobs')),
          ),
        ),
      ],
    ),
  ],
);

Solution

  • The error you're seeing indicates that the route isn't being matched as expected. By making the path explicit or adding better debugging or fallback routes, you should be able to resolve the issue and see why the simulator isn't displaying the Jobs page as intended.

    final router = GoRouter(
      routes: [
        GoRoute(
          path: '/',
          builder: (_, __) => Scaffold(
            appBar: AppBar(title: const Text('Home Screen')),
          ),
          routes: [
            GoRoute(
              path: 'jobs/:jobTitle', // Explicitly match job titles
              builder: (_, state) => Scaffold(
                appBar: AppBar(title: const Text('Jobs')),
                body: Center(child: Text('Job Title: ${state.params['jobTitle']}')),
              ),
            ),
          ],
        ),
      ],
    );
    

    Hope this help