Remove leading `#` from URL of Flutter web app

continue from above

Author: Nuts

Official Account: " Big Front-End Tour "

Huawei cloud sharing expert, InfoQ contract author, Alibaba Cloud expert blogger, 51CTO blog chief experience officer, one of the members of the open source project GVA , focusing on the sharing of big front-end technologies, including Flutter, applet, Android, VUE, JavaScript.

Then, did you find that there is a # on it? To be honest, I am also very annoying, so how to solve it is actually very simple. import the following packages

url_strategy: ^0.2.0

image-20220307083936412

How to install it? console run

flutter pub add url_strategy

url_strategy

Flutter app bundle that allows setting web URL policies with a single line of code.

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

There will now be no leading in the URL of your Flutter web app #.

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

image-20220307084109551

So have you seen it? Oh no.

Guess you like

Origin blog.csdn.net/qq_39132095/article/details/123321815