搜索插件、代码仓与 APP 分类

插件详情v0.3.0

url_strategy

Flutter 包,可通过一行代码设置 Web 应用的 URL 策略。

AndroidiOSLinuxmacOSWebWindows
近 30 天下载
10.8万
喜欢数
554
Pub 分数
160

安装插件

flutter pub add url_strategy

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

url_strategy 包通过一行代码设置 URL 策略,使 Flutter Web 应用程序能够使用简洁、可读性强的 URL。它允许开发者在基于哈希的路由(例如 /#/home)和基于路径的路由(例如 /home)之间切换,从而提升 SEO 效果和用户体验。该包轻量且专为 Flutter Web 设计,确保无缝集成而无需额外配置。它支持所有主要平台,包括 Web、Android、iOS、Linux、macOS 和 Windows。

适合场景

  • 在 Flutter Web 应用中启用干净的 URL
  • 改进基于Web的Flutter应用的SEO
  • 简化仅限 Web 的 Flutter 项目中的导航
  • 支持 Web 应用中的深度链接
  • 跨平台保持路由一致性

主要特点

  • 单行URL策略设置
  • 支持哈希和路径两种路由方式
  • 轻量级且开销极小
  • 跨平台兼容性
  • 轻松集成到现有的 Flutter Web 项目中

适合对象

  • Flutter 开发者构建 Web 应用
  • 需要SEO友好URL的项目
  • 使用深度链接或共享链接的应用
  • 注重清晰URL结构的团队
  • 面向 Web 部署的开发者

使用建议

  • 仅适用于Web部署
  • 需要正确的服务器配置以支持基于路径的路由
  • 移动应用专用的 Flutter 应用无需此功能
  • 可能需要为生产环境托管调整后端
  • 在 Web 上下文之外的用途有限

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

url_strategy Pub version

⚠️ Discontinued: The functionality is now provided by the flutter SDK out of the box:

https://docs.flutter.dev/ui/navigation/url-strategies

Package for Flutter apps that allows setting the web URL strategy with a single line of code.

Usage

With a simple call of setPathUrlStrategy, your Flutter web app does not have a leading # in the URL anymore 🚀

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());
}

See the url_strategy package README or the explanation on StackOverflow for more detailed usage documentation.

Implementation

The package is basically a wrapper around the flutter_web_plugins setUrlStrategy. The reason it exists is that using the function from flutter_web_plugins requires conditional imports.
The problem is solved by using a conditional export from the url_strategy package.

所属分类

源码仓库

使用此插件的项目

暂无相关数据。