Flutter Web项目的默认URL定义包含标签(#)的URL,如下所示:

http://localhost:41521/#/peaple/...

我想删除此‘#’,如下所示:

http://localhost:41521/peaple/

我怎样才能解决这个问题?

推荐答案

现在,你可以使用simple package102从你的Flatter web应用程序100(完全公开:我是作者)中删除前导散列(#)

Using 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上).

Flutter相关问答推荐

类型int不是可迭代动态tmdbapi类型的子类型<>

在Flutter TextField中计算子字符串位置

从超级应用程序启动时,Flutter 小应用程序中未加载资源

如何实现Flutter 梳理机图像的小量移动

在Ffltter中,我已经使用了Ffltter_BLOC Cupit和Pusher,但当获得新数据时,UI没有更新

Flutter:使用 GlobalKey 访问 BlocProvider

为什么我们需要使用ChangeNotifierProvider而不是仅仅使用ChangeNotifier?

Flutter列顶部和底部出现不必要的边距问题

如何正确地将 PageView 设置为 AppBar 的标题?

提供者、存储库和服务之间有什么区别?

我的第一个 flutter 项目出错,启动时为空值?

graphql_flutter 错误:非抽象类GraphQLWebSocketChannel缺少实现

无法在 flutter 中更新 void 方法内的变量值

在 Flutter 中更改高架按钮 OnPressed 的背景 colored颜色

如何在椭圆形图像周围添加边框?Flutter

我一直在try 创建按钮以导航到第二页,但不知何故 RaisedButton 功能无法正常工作

如何使用 Navigator 2.0 导航到任何页面?

Flutter NavigationBar 忽略我的背景 colored颜色

如何在Flutter 中制作自定义微调器?

Flutter audioplayers错误-单击音频按钮时不播放音频