csells / go_router

The purpose of the go_router for Flutter is to use declarative routes to reduce complexity, regardless of the platform you're targeting (mobile, web, desktop), handling deep linking from Android, iOS and the web while still allowing an easy-to-use developer experience.
https://gorouter.dev
441 stars 97 forks source link

Added routerNeglect option to GoRouter. #262

Closed nullrocket closed 2 years ago

nullrocket commented 2 years ago

Added routerNeglect option to GoRouter. Added router_neglect.dart example. Updated examples list in docs.

Not sure about how you want to document this, I did create an example for it.

:sparkles: What kind of change does this PR introduce? (Bug fix, feature, docs update...)

Adds optional flag routerNeglect to suppress creation of history entries on the web.

:arrow_heading_down: What is the current behavior?

No way to suppress web history outside of go_router.

:new: What is the new behavior (if this is a feature change)?

Allows globally disabling history creation on the web. Global meaning as long as they are using go_router. Any other navigation methods outside of go_router have to be wrapped by the developer manually.

:boom: Does this PR introduce a breaking change?

No

:bug: Recommendations for testing

All tests pass, and all examples run, I can't work out a way to automatically test that no history entries are created that would be worth automating, looking at the flutter tests for Router.neglect didn't reveal any insight.

:memo: Links to relevant issues/docs

https://github.com/csells/go_router/issues/226

:thinking: Checklist before submitting

nullrocket commented 2 years ago

Sorry about all the noise around validate/style. I always forget 160 != 80. I can't deal with short lines. Pre-commit hooks are awesome until you rely on them and they are not there :)

csells commented 2 years ago

I'll check this out. in the meantime, there needs to be some mention in the docs. can you work on that @nullrocket ?

csells commented 2 years ago

If I've got routerNeglect set to true, which the use of Router.neglect when calling GoRouter.push?

csells commented 2 years ago

It doesn't look like Router.neglect is needed when using routerNeglect: true. However, it works nicely on a per navigation event when you're using routerNeglect.false. I think the story for the docs would be something along the lines of the following:

Sometimes you don't want the browser tracking history when you navigate. In that case, use Router.neglect (snippet). And if you'd like the browser to stop tracking history altogether for your app, use routerNeglect: true (snippet).

Nice!

nullrocket commented 2 years ago

@csells Ahh, yeah the example should have been using navigator on that button labeled Navigator.push to show how to get the effect outside go_router. Fixed.

I'll work on the docs.