Skip to content

[web] Remove the trailing /#/ on home pages #127608

@mdebbar

Description

@mdebbar

With the HashUrlStrategy, we add the hash fragment for all pages, including the home page (i.e. routeName = "/"). This means the landing page of the app always has a trailing /#/ in the URL (e.g. https://gallery.flutter.dev/#/).

One thing we can do to improve this is to have a special case for the / and the empty route name such that they don't add the hash fragment to the URL.

Users can already do this in their apps:

import 'package:flutter/material.dart';
import 'package:flutter_web_plugins/url_strategy.dart';

class MyUrlStrategy extends HashUrlStrategy {
  @override
  String prepareExternalUrl(String internalUrl) {
    final String externalUrl = super.prepareExternalUrl(internalUrl);
    if (externalUrl.endsWith('#/')) {
      return externalUrl.substring(0, externalUrl.length - 2);
    }
    return externalUrl;
  }
}

void main() {
  setUrlStrategy(MyUrlStrategy());
  runApp(MyApp());
}

This issue is for making this the default behavior of HashUrlStrategy. cc @johnpryan @kevmoo

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listengineflutter/engine related. See also e: labels.f: routesNavigator, Router, and related APIs.platform-webWeb applications specifically

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions