skip to Main Content

I’m trying to handle a deeplink using the autoRoute package, how can I make my deeplink work when the url is opened?

here is my deeplink handler code

MaterialApp.router(
        title: 'Flutter Demo',
        routerConfig: _appRouter.config(
          navigatorObservers: () => [AutoRouteObserver()],
    deepLinkBuilder: (link) {
            print(link.path);
            if(link.path.startsWith('/ru/reset-password')) {
              return const DeepLink(
                [ResetPassRoute()]
              );
            } else {
              return DeepLink.defaultPath;
            }
    }
        ),
      ),


/// route config 
@AutoRouterConfig()
class AppRouter extends _$AppRouter {
  @override
  List<AutoRoute> get routes => [
        AutoRoute(page: MainRoute.page, initial: true, children: [
          AutoRoute(page: HomeRoute.page),
          AutoRoute(page: HelpRoute.page),
          AutoRoute(page: AboutRoute.page),
          AutoRoute(page: ContactsRoute.page),
          AutoRoute(page: ConfidenceRoute.page),
          AutoRoute(page: TermsRoute.page),
          AutoRoute(page: FavoriteRoute.page),
          AutoRoute(page: CreateRoute.page),
          AutoRoute(page: MessageRoute.page),
          AutoRoute(page: ProfileRoute.page),
          AutoRoute(page: RegistrationRoute.page),
        ]),
        AutoRoute(page: RegistrationRoute.page),
        AutoRoute(page: ResetPassRoute.page),
      ];
}

when I open my url my-url/ru/reset-password nothing happend, how can i fix it?

2

Answers


  1. Make sure you’ve setup your AndroidManifest.xml and Info.plist files to handle the deep links.

    For AndroidManifest.xml you can add something like this:

    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="http"
              android:host="my-url" />
    </intent-filter>
    

    For Info.plist you can add something like this:

    <key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>my-url</string>
            </array>
        </dict>
    </array>
    
    Login or Signup to reply.
  2. Please check your condition and try this :

       MaterialApp.router(
            title: 'Flutter Demo',
            routerConfig: _appRouter.config(
              navigatorObservers: () => [AutoRouteObserver()],
            deepLinkBuilder: (link) {
                print(link.path);
                if(link.path.contains('/ru/reset-password')) {
                  return const DeepLink(
                    [ResetPassRoute()]
                  );
                } else {
                  return DeepLink.defaultPath;
                }
              }
            ),
          ),
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search