[Breaking Change] Allow gaps in the Navigator's initial route

108 views
Skip to first unread message

Mouad Debbar

unread,
Sep 4, 2019, 1:04:46 PM9/4/19
to flutter-...@googlegroups.com

Background

The Navigator widget (and WidgetsApp and MaterialApp) takes an `initialRoute` parameter that specifies what route to push when the app is launched. This is used for deep linking in mobile apps. It's also useful on the web for linking directly to a specific screen in the app.

Current behavior

Assuming the given initial route is `/A/B/C`. The app would try to push the following routes: `/`, `/A`, `/A/B`, `/A/B/C`. If any of these paths doesn't map to a route in the app, the initial route is ignored and the default route is used instead (`/`).

New behavior

In the example above, as long as `/` and `/A/B/C` are valid routes in the app, then the initial route is honored, and any non-existent intermediate routes are skipped (e.g. `/A` or `/A/B`).

Motivation

On the web, users rely a lot on the browser's refresh functionality and the expectation is to remain on the same screen after the page is reloaded. With the current behavior, this expectation isn't met.

For an example, the flutter gallery today has material demos with routes like `/material/buttons` but the flutter gallery doesn't define a route for `/material`. So when someone attempts to deep link to the material buttons demo page, the app fails and falls back to the home screen because it can't push the intermediate route `/material`.

This translates to users on the web refreshing the page of material buttons demo and finding themselves in the home screen instead.

Impact

If there are apps out there that have deep links with gaps, they used to fail before and the deep link would land them on the home screen. After the change, those same deep links will start working and landing on the desired screen (assuming there is one).


Reply all
Reply to author
Forward
0 new messages