How do I detect if app was launched with a route in Flutter web?

Solution 1:

If you don't want to use Navigator 2 (recommended way of handling navigation when you target web), solution is to use MaterialApp.onGenerateInitialRoutes.

This callback gets called when MaterialApp starts with a given route (in case of Web - URL). In it, you can detect if route requires any additional setup, push some kind of "splash" page which will perform the loading and then redirect to requested route, example implementation below:

MaterialApp(
  // ...
  onGenerateInitialRoutes: (navigator, route) => [
    MaterialPageRoute(
      builder: (context) => SplashScreen(), 
      settings: RouteSettings(
        arguments: SplashScreenArgs(destinationRoute: transformDeeplink(route)),
      ),
    ],
  ),
),

Notice the transformDeeplink function here - you should implement your own logic to decide if entering your app with given route should be allowed. Redirect to other (default) route or display some kind of error page if not.