url_strategy 0.3.0 copy "url_strategy: ^0.3.0" to clipboard
url_strategy: ^0.3.0 copied to clipboard

Flutter package that allows setting the web app URL strategy with a single line of code.

url_strategy GitHub stars #

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

Usage #

To use this plugin, follow the installing guide.

Setting the URL strategy #

If you want to remove the leading hash (#) from the URL of your Flutter web app, you can simply call setPathUrlStrategy in the main function of your app:

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

Now, your Flutter web app will not have a leading # in the URL anymore.

It is safe to call the function even when running on any other platform than web (which is the point of this package). That means that you can safely call setPathUrlStrategy when running on mobile or desktop - it will simply be a noop.

Base

Make sure that you have <base href="/"> included inside the <head> section of your web/index.html if you want to use the path URL strategy.
This is included by default when you create a new Flutter project.

Furthermore, you need to ensure that your production HTTP server always serves your web/index.html file for all paths.

See this more detailed StackOverflow answer for more information.

Hash strategy

You can also use a hash URL strategy instead (which is the default) by calling setHashUrlStrategy.

547
likes
160
points
133k
downloads

Publisher

verified publishersimpleclub.com

Weekly Downloads

Flutter package that allows setting the web app URL strategy with a single line of code.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter_web_plugins

More

Packages that depend on url_strategy