2

Which is the best way of Routing in a Flutter App? I've tried named routes, routes array, flutter navigation 2.0. But I am still not sure which is the best.

moboldi
  • 51
  • 1
  • 8

2 Answers2

3

Flutter docs suggests using go_router package for Navigation.


Explanation:

Limitations of trivial approach

Although named routes can handle deep links, the behavior is always the same and can’t be customized. When a new deep link is received by the platform, Flutter pushes a new Route onto the Navigator regardless where the user currently is.

Suggested Better Approach

Flutter applications with advanced navigation and routing requirements (such as a web app that uses direct links to each screen, or an app with multiple Navigator widgets) should use a routing package such as go_router that can parse the route path and configure the Navigator whenever the app receives a new deep link.


Reference questions regarding go_router:

krishnaacharyaa
  • 14,953
  • 4
  • 49
  • 88
1

Navigator 1.0 and 2.0 are usable. None is deprecated.

For mobile app only Navigator 1.0 is the best, I use onGenerateRoute field from MaterialApp and that's all I can handle all my routes and deep links. Some times, I used the Navigator widget for specific routes in app page but it's rare.

Eng
  • 1,617
  • 2
  • 12
  • 25