在Flutter网站上重新加载页面时“未找到”

时间:2019-09-17 18:30:20

标签: flutter dart flutter-web

在Flutter Web上,当我在Chrome上重新加载页面时,显示文本“未找到”。我该如何解决?这是我的main.dart代码。我还注意到,要直接进入页面,我必须在网址中插入一个井号(#),如下所示:“ http://127.0.0.1:8080/#/homepage”。有办法将其删除吗?

class MyApp extends StatefulWidget {

const MyApp({Key key}): super(key: key);

@override
MyAppState createState() => MyAppState();
}

class MyAppState extends State<MyApp> {
// This widget is the root of your application.

@override
  void initState() {
  html.window.history.pushState(null, "Home", "/");
  super.initState();
}

@override
Widget build(BuildContext context) {
  return MaterialApp(
    title: 'Flutter Demo',
    initialRoute: "/",
    theme: ThemeData(
      primarySwatch: Colors.blue,
      fontFamily: 'GoogleSansRegular'
    ),
    routes: {
      "/": (context) => HomePage(),
      "/homepage": (context) => HomePage(),
      "/secondPage": (context) => SecondPage()
    },
  );
}
}

0 个答案:

没有答案