When i try to navigate to public page by direct url http://localhost:60345/#/public
, i am first redirected to initial route, which is /home
. And if i go to http://localhost:60345/#/public
again in the same tab, i get Public page.
If i open a new tab, the problem exists for the first time and from the second, i get the correct page /public
.
MaterialApp(
debugShowCheckedModeBanner: false,
builder: (context, child) {
final MediaQueryData data = MediaQuery.of(context);
final textScaleFactor = MediaQuery.of(context).textScaleFactor.clamp(
0.9,
1.18,
);
return MediaQuery(
data: data.copyWith(textScaleFactor: textScaleFactor),
child: child ?? Container());
},
navigatorKey: getIt<NavigationService>().getNavigatorKey(),
initialRoute: '/home',
onGenerateRoute: (RouteSettings settings) {
switch (settings.name) {
case '/public':
return MaterialPageRoute(builder: (_) => PublicPage());
case '/home':
return MaterialPageRoute(builder: (_) => HomePage());
default:
return MaterialPageRoute(
builder: (_) => Container(
child: Center(
child: Text('Default'),
),
));
}
},
navigatorObservers: [
FirebaseAnalyticsObserver(
analytics: AnalyticService().getFirebaseAnalytics()),
CustomNavigatorObserver()
],
supportedLocales: const [
Locale('en', ''), // English, no country code
],
locale: const Locale('en', ''),
localizationsDelegates: const [
AppLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate
],
title: AppConfig.of(context).appTitle,
theme: kIsWeb ? wedTheme : defaultTheme,
)
Home Page:
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Home Page'),
),
body: Center(
child: Text('Welcome to the Home Page!'),
),
);
}
}
Public Page:
class PublicPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Public Page'),
),
body: Center(
child: Text('Welcome to the Public Page!'),
),
);
}
}
Video
http://localhost:60345/#/public
should load the correct page in first load.