1

I want to know why is there a hashtag in the URL? for the Flutter web app, eg: http://localhost:64392/#/home even in production same result.

I want to know why and also if possible to remove it?

lordyhas
  • 360
  • 1
  • 11

1 Answers1

4

To remove the # in the URL, it is documented here:

To configure Flutter to use the path instead, use the usePathUrlStrategy function provided by the flutter_web_plugins library in the SDK:

import 'package:flutter_web_plugins/url_strategy.dart';

void main() {
  usePathUrlStrategy();
  runApp(ExampleApp());
}

And add this to your pubsepc.yaml:

dependencies:
  flutter:
    sdk: flutter
  flutter_web_plugins:
    sdk: flutter


Additionally, you can use the go_router package.

See turning off the hash:

void main() {
  // turn on the # in the URLs on the web (default)
  // GoRouter.setUrlPathStrategy(UrlPathStrategy.hash);

  // turn off the # in the URLs on the web
  GoRouter.setUrlPathStrategy(UrlPathStrategy.path);

  runApp(App());
}
MendelG
  • 14,885
  • 4
  • 25
  • 52
  • okay thanks, that's helpful, but do you know why is there a hashtag in the URL? by default – lordyhas Dec 29 '22 at 15:33
  • @lordyhas Not sure why, that's just the way it works.. – MendelG Dec 29 '22 at 16:55
  • 2
    It seams the "#" character tells the browser that this is a client-side route and that the navigation should be handled by the application, rather than making a new request to the server. Flutter uses the hashtag convention by default to provide a consistent and predictable URL structure for client-side routing. – user1959018 May 04 '23 at 18:24