Dazza is a general routing framework for Dart applications. It is designed to be fast, yet flexible.
Dazza has only the coolest features:
- Wildcard / named route parameters (e.g.:
/users/:id
) - Query string parameter support
- Pass custom parameters when evaluating routes
- Global context for route handlers (allows for immutable, shared values to be passed to each invocation)
- Result value for handler calls
- Easily extended for custom routing needs
Dazza require Dart 2.0+. Dart 2.0 is awesome.
To install, add the following line to the dependencies
section of your pubspec.yaml
file:
dependencies:
...
dazza: ^1.0.0
You can then import dazza using:
import 'package:dazza/dazza.dart';
To define routes you need a Router
instance:
final router = Router(
noMatchHandler: Handler(callback: noMatchCallback),
);
NOTE: Your Router
instance should be stored somewhere where you can easily access it in multiple places as you will probably only ever want one Router
instance per application.
Now you can define your routes. Routes can take the form of regular routes or can contained named parameters. Named parameters start with a colon (:). For example, /users/:id
. To define your routes:
router.addRoute(RouteDefinition.withCallback("/users/:id", callback: usersRouteCallback));
Route callbacks are defined as functions, such as:
dynamic usersRouteCallback(Parameters parameters, dynamic context) {
int userId = parameters.firstInt("id");
...
return userId;
}
Or you can define them in-line if you need:
router.addRoute(
RouteDefinition.withCallback("/users/:id",
callback: (Parameters parameters, dynamic context) {
int userId = parameters.firstInt("id");
...
return userId;
}),
);
We prefer you use whatever you want. Dazza is, most likely, no better or worse than the alternatives.
Dazza was designed from the ground up to serve as a generic routing mechanism based on our experience with Dart usage on the web and in Flutter. Dazza is what we wanted out of a good routing framework, not a copy of any specific framework or best practices. It has the features we think are important, and is architected in a way that we think makes managing all this stuff super simple.
Give it a try and if you like it, let us know! Either way, we love feedback.
The code here is derived from the code that was written for Fluro (https://github.com/goposse/fluro). Fluro has been battle tested in the hamilton app in production and is used by millions of people. Dazza is also in use serving Firebase Functions in other apps. That said, code is always evolving. We plan to keep on using it in production but we also plan to keep on improving it. If you find a bug, let us know!
The following projects use dazza:
- Cumulus: Firebase logic made easy (by Yakka). Link
Dazza is sponsored, owned and maintained by Yakka LLC. Feel free to reach out with suggestions, ideas or to say hey.
If you believe you have identified a serious security vulnerability or issue with Dazza, please report it as soon as possible to [email protected]. Please refrain from posting it to the public issue tracker so that we have a chance to address it and notify everyone accordingly.
Dazza is released under a modified MIT license. See LICENSE for details.