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
441 stars 97 forks source link

redirect without page stack #387

Closed Fiyiin closed 2 years ago

Fiyiin commented 2 years ago
GoRouter(
      routes: [
      ...
        GoRoute(
          name: 'register',
          path: '/auth/register',
          builder: (context, state) => SignUpScreen(),
          routes: [
            GoRoute(
              name: 'phone',
              path: 'phone',
              builder: (context, state) => PhoneNumberScreen(),
              routes: [
                GoRoute(
                  name: 'verify',
                  path: 'verify',
                  builder: (context, state) => VerifyPhoneNumberScreen(),
                ),
              ],
            ),
          ],
        ),
       ...
      ],
      redirect: (state) {
        final isVerified = user.isVerified!;
        final isVerifying = state.subloc == '/auth/register/phone';
        if (!isVerified) return isVerifying ? null : ''/auth/register/phone';
        return null;
      },
    );

When the route is redirected to /auth/register/phone, I only want the subroute phone to be pushed onto the stack. Kinda the way context.push() works, how do I achieve this?