Clarified '/' route in initialRoute docs#64793
Clarified '/' route in initialRoute docs#64793markusaksli-nc wants to merge 0 commit intoflutter:masterfrom
Conversation
|
It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat. Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
|
@chunhtai Not that familiar with the new Router API yet, maybe something can be added to mention that?
From the doc |
|
Could you please explain the reason why the |
|
@sidrao2006 I thought the reasoning was implicit enough. The reason was that if you want to use a named route scheme with names like If you have defined If you have not defined Only if you want to push a different root depending on the launch context would you leave Obviously these are not hard rules, once a user is familiar with routes they can do as they please with the system. This is simply to deter new users from getting confused when attempting to use I fear this might be too verbose since this is just targeted at new users but I could add it if necessary. |
|
Ok thanks a lot. I just figured out that I was using |
It is not better, it just less boiler plate when you don't care about routing. It essentially just push a route '/' to the navigator with its content = home. |
| /// | ||
| /// Even if the route was just `/a`, the app would start with `/` and `/a` | ||
| /// loaded. This is why it is preferable to avoid hardcoding a deep link | ||
| /// [initialRoute] to simply set the default route of the app. The [home] |
There was a problem hiding this comment.
I don't think we should encourage the usage of home for this reason. home is just less boilerplate code and may be confusing when uses with the WidgetsApp.routes
| /// also. For example, if the route was `/a/b/c`, then the app would start | ||
| /// with the four routes `/`, `/a`, `/a/b`, and `/a/b/c` loaded, in that order. | ||
| /// | ||
| /// Even if the route was just `/a`, the app would start with `/` and `/a` |
There was a problem hiding this comment.
would be good to mention that you can provide onGenerateInitialRoutes to override this behavior
pages api is not available in WidgetsApp, so you don't need to worry about it here |
|
@chunhtai Yeah I agree, the suggestion to use home isn't that justified. I committed the changes. |
|
This pull request is not suitable for automatic merging in its current state.
|
|
@markusaksli-nc Can you rebase off the master to see if it fixes the failing test? |
dd22bf5 to
54ade88
Compare
|
Fork master was behind so the rebase got really messy, I'll just make a clean PR |
Description
This PR clarifies the fact that Navigator will always load the
/route as the root of initialRoute deep links and that even simple routes like/awill be treated as deep links (this would mean two routes are pushed). This is to deter new users from trying to use this property when they could just usehomeorroutes: { '/': (context) =>...instead. The resulting confusion can be seen in the linked issue.Related Issues
Fixes #64775
Tests
Not necessary, this is a documentation PR.
Checklist
Before you create this PR, confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]). This will ensure a smooth and quick review process.///).flutter analyze --flutter-repo) does not report any problems on my PR.Breaking Change
Did any tests fail when you ran them? Please read Handling breaking changes.