Flutter Web项目的默认URL定义包含标签(#
)的URL,如下所示:
http://localhost:41521/#/peaple/...
我想删除此‘#’,如下所示:
http://localhost:41521/peaple/
我怎样才能解决这个问题?
Flutter Web项目的默认URL定义包含标签(#
)的URL,如下所示:
http://localhost:41521/#/peaple/...
我想删除此‘#’,如下所示:
http://localhost:41521/peaple/
我怎样才能解决这个问题?
现在,你可以使用simple package和102从你的Flatter web应用程序100(完全公开:我是作者)中删除前导散列(#)
url_strategy
您只需添加依赖项as described here,然后将以下函数调用添加到main
函数:
import 'package:url_strategy/url_strategy.dart';
void main() {
// Here we set the URL strategy for our web app.
// It is safe to call this function when running on mobile or desktop as well.
setPathUrlStrategy();
runApp(MyApp());
}
打setPathUrlStrategy
就够了?
该软件包还确保了在移动设备上运行代码不会崩溃(见下文).此外,如果您在stable
上构建移动应用程序,而仅在beta
上构建Web应用程序,则这也将在stable
上运行.
You need to make sure that you include <base href="/">
inside the <head>
section of your web/index.html
when using the path URL strategy.
This is added by default when creating a new Flutter app.
Furthermore, when deploying your production app, you need to make sure that every path points to your index.html
. If you use tools like Firebase hosting, this is done automatically for you when configuring your app as a single page app.
Otherwise, you want to look up how to rewrite all paths to your index.html
for the hosting you are using.
本质上,您希望有一个单页应用程序,其中HTTP服务器为所有路径提供index.html
条服务.
包实现基于使用flutter_web_plugins
的手动解决方案.使用该软件包的好处如下:
stable
上不会出现任何缺少的实现问题(因为web功能仍然在beta
上).