yawg567
yawg567

Reputation: 121

Flutter web custom url route results in 404

I'm using flutter web to build a website. I have two main routes in my website, a LoginPage which also is the initialRoute and a HomePage. I'm using Get to move between routes and I set up the path navigation strategy using the url_strategy package.

Main.dart

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  setPathUrlStrategy();
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return GetMaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'website',
      unknownRoute: GetPage(
        name: '/notfound',
        page: () => UnknownRoutePage(),
      ),
      initialRoute: '/LoginPage',
      getPages: [
        GetPage(
          name: '/LoginPage',
          page: () => LoginPage(),
        ),
        GetPage(
          name: '/HomePage',
          page: () => HomePage(),
        )
      ],
    );
  }
}

Meanwhile everything works fine when I'm debugging on my pc (even with flutter run --release) I get problems when I deploy the website on Firebase Hosting.

Let's say I try to reload a page (like for example www.website.com/LoginPage) I get the default page not found from Firebase Hosting (even if I set a custom notfound page) while I sould expect to be redirected to the LoginPage of my website.

How can I resolve this problem?

Upvotes: 2

Views: 1201

Answers (1)

yawg567
yawg567

Reputation: 121

I figured out how to resolve this issue, just added

"rewrites": [ {
   "source": "**",
   "destination": "/index.html"
} ]

to my firebase.json file.

Upvotes: 8

Related Questions