Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ShellRoute deeplink not working if it's path isn't '/' #8

Open
pierremrtn opened this issue Jul 18, 2022 · 0 comments
Open

ShellRoute deeplink not working if it's path isn't '/' #8

pierremrtn opened this issue Jul 18, 2022 · 0 comments

Comments

@pierremrtn
Copy link

Hello,

I think I've encountered a bug with ShellRoute. Considering the following router setup, I'm not able to navigate to /shell/child when entering url in navigator (chrome):

  final GoRouter _router = GoRouter(
    routes: [
      StackedRoute(
        path: '/',
        builder: (context) => const DummyPage(),
      ),
      ShellRoute(
        path: '/shell',
        builder: (context, child) => Scaffold(
          body: child,
          appBar: AppBar(title: const Text('Shell')),
        ),
        routes: [
          StackedRoute(
            path: 'child',
            builder: (context) => const DummyPage(),
          ),
        ],
      ),
      StackedRoute(
        path: '/other',
        builder: (context) => const DummyPage(),
      ),
    ],
  );

I'm able to navigate to /, /shell, and /other, but when I'm entering /shell/child in the url I'm redirected to /.
The problem disappears if I set the ShellRoute path to / instead of /shell.

Here is a minimal reproducible example.

import 'package:flutter/material.dart';
import 'package:go_router_prototype/go_router_prototype.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  runApp(App());
}

class App extends StatelessWidget {
  App({
    super.key,
  });

  final GoRouter _router = GoRouter(
    routes: [
      StackedRoute(
        path: '/',
        builder: (context) => const DummyPage(),
      ),
      ShellRoute(
        path: '/shell',
        builder: (context, child) => Scaffold(
          body: child,
          appBar: AppBar(title: const Text('Shell')),
        ),
        routes: [
          StackedRoute(
            path: 'child',
            builder: (context) => const DummyPage(),
          ),
        ],
      ),
      StackedRoute(
        path: '/other',
        builder: (context) => const DummyPage(),
      ),
    ],
  );

  @override
  Widget build(BuildContext context) {
    return MaterialApp.router(
      routeInformationParser: _router.parser,
      routerDelegate: _router.delegate,
    );
  }
}

class DummyPage extends StatelessWidget {
  const DummyPage({
    super.key,
  });

  @override
  Widget build(BuildContext context) {
    return Center(
      child: Text(RouteState.of(context).route.path),
    );
  }
}

I hope I'm not disrupting this project by opening this issue since it's only a prototype.
Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant