csells / go_router

The purpose of the go_router for Flutter is to use declarative routes to reduce complexity, regardless of the platform you're targeting (mobile, web, desktop), handling deep linking from Android, iOS and the web while still allowing an easy-to-use developer experience.
https://gorouter.dev
442 stars 96 forks source link

route name lookup seems to be case sensitive #132

Closed pryshrm closed 2 years ago

pryshrm commented 2 years ago

Given the router configuration below,

This works: GoRouter.of(context!).pushNamed(**'note1'**, params: {'noteid': id!.toString()},);

and This does not work : GoRouter.of(context!).goNamed(**'tab1AndNote1'**, params: {'noteid': id!.toString()},);

Exception: unknown route name: tab1AndNote1

So, my question is can the name given to the uppermost path segment ( here, tab1AndNote1 ) ever be used as a name?

I have the following go router configuration:

final _router = GoRouter(
    routes: [
      GoRoute(
        name: 'root',
        path: '/',
        pageBuilder: (context, state) {
          return MaterialPage<void>(
            key: state.pageKey,
            child: const MainAppScreen(),
          );
        },
      ),
      GoRoute(
        name: 'tab1AndNote1',
        path: '/tab1',
        pageBuilder: (context, state) {
          return MaterialPage<void>(
            key: state.pageKey,
            child: const MainAppScreen(),
          );
        },
        routes: [
          GoRoute(
            name: 'note1',
            path: 'note1/:noteid',
            pageBuilder: (context, state) {
              int noteid = int.tryParse(state.params['noteid'] ?? "0") ?? 0;
              return MaterialPage<void>(
                key: state.pageKey,
                child: NoteDetailScreen(noteid: noteid),
              );
            },
          ),
        ],
      ),
    ],
  );
csells commented 2 years ago

@pryshrm can you post a complete but minimal repro project that demonstrates this issue? The behavior you're asking for works in all of my testing (a lot). I suspect something else is causing the issue.

pryshrm commented 2 years ago

I found the issue. In the GoRouter configuration (posted above), I have specified the name as 'tab1AndNote1' (notice the casing). Although, when calling goNamed(), I am using the same name with the exact same case but that doesn't work. However, when I changed the name to all lower case, it worked. i.e. goNamed('tab1andnote1', ...) is working....even though, in the configuration, the name is tab1AndNote1.

I found this out after I set debugLogDiagnostics: true. It printed out the name for the route as tab1andnote1 (all lower case).

So, the question now is, is this expected?

csells commented 2 years ago

Ah. Name lookup should be case insensitive. I'll take a look.

pryshrm commented 2 years ago

As of now, it is neither case sensitive nor case insensitive because, as of now, route name tab1AndNote1 is matched only with goNamed('tab1andnote1').

csells commented 2 years ago

this should be fixed in v2.2.3. @pryshrm can you confirm?