1

So I set my routes up like this:

I set my initial route:

 initialRoute: "/",

& then my onGenerateRoutes:

  onGenerateRoute: (settings) {
    switch (settings.name) {
      case HomePage.route:
        int? selectedIndex = settings.arguments as int?;
        return MaterialPageRoute(
            builder: (context) =>
                HomePage(selectedIndex: selectedIndex ?? 0));
      case FPassword.route:
        return MaterialPageRoute(
          builder: (context) => const FPassword(),
        );
    }
  },

Im saving the route itself in each corresponding class:

static const String route = '/password';

& im navigating like:

onTap: () => Navigator.pushNamed(
                          context, HomePage.route,
                          arguments: 0),

But the problem that Im facing is that the route itself isnt appearing in my domain, it always stays like:

http://localhost:61694/#/

It doesnt change. I already ran pub clean, started everything anew & so on. So where have I made my mistake?

Nikita
  • 477
  • 4
  • 14

1 Answers1

0

Define the routes something like this:

MaterialApp(
  title: 'Named Routes Demo',
  initialRoute: '/',
  routes: {
    '/': (context) => const FirstScreen(),
    '/second': (context) => const SecondScreen(),
  },
)

See Navigate with named routes for details.

Paths written without a hash e.g foo.bar/second:

import 'package:flutter_web_plugins/url_strategy.dart';

void main() {
  usePathUrlStrategy();
  runApp(App());
}

See Configuring the URL strategy on the web for details.

user18309290
  • 5,777
  • 2
  • 4
  • 22