m4d_router 0.2.5

  • README.md
  • Installing
  • Versions
  • new59

Material4Dart router

m4d_router is a client routing library for Dart. It helps make building single-page web apps and using HttpServer easier.



Add this package to your pubspec.yaml file:

  m4d_router: any

Then, run pub get to download and link in the package.


Live: m4d_router.example.mikemitterer.at
Source - check it out on GitHub

void main() {
    final router = new Router();

    configLogging(show: Level.INFO);

    dom.querySelector('#output').text = 'Your Dart app is running.';

void _configRouter(final Router router ) {

        ..addRoute(name: "Test I", path: new UrlPattern('/#/test'),
            enter: (final RouteEnterEvent event) {
                _logger.info("Path: ${event.path} Params: ${event.params.join(",")}");

        ..addRoute(name: 'Cats', path: new ReactPattern('/cats'),
            enter: (final RouteEnterEvent event) {
                _logger.info("Path: ${event.path} Params: ${event.params.join(",")}");

        ..addRoute(name: 'Specific cat', path: new ReactPattern(r'/cats/(\w+)'),
            enter: (final RouteEnterEvent event) {
                _log("${event.route.title}: ${event.params.join(",")}");
                _logger.info("Path: ${event.path} Params: ${event.params.join(",")}");
                if(event.params.first.toLowerCase() == "grumpy") {
                } else {

        ..addRoute(name: "Google for cats", path: new ReactPattern('/google'),
            enter: (final RouteEnterEvent event) {
                _logger.info("Path: ${event.path} Params: ${event.params.join(",")}");

    // optional
    router.onEnter.listen((final RouteEnterEvent event) {
        _logger.info("RoutEvent ${event.route.title} -> ${event.route.urlPattern.pattern}");

    // optional
    router.onError.listen((final RouteErrorEvent event) {
        _logger.info("RouteErrorEvent ${event.exception}");

    router.listen(); // Start listening

void _log(final String logMessage) {
    final logElement = dom.querySelector("#log") as dom.UListElement;
    logElement.append(new dom.LIElement()..text = logMessage);

void _showImage(final String url) {
    final img = dom.querySelector("img") as dom.ImageElement;
    img.src = url;


Route is built around UrlPattern a class that matches, parses and produces URLs. A UrlPattern is similar to a regex, but constrained so that it is reversible, given a UrlPattern and a set of arguments you can produce the URL that when parsed returns those same arguments. This is important for keeping the URL space for your app flexible so that you can change a URL for a resource in one place and keep your app working.

Route lets you use the same URL patterns for client-side and server-side routing. Just define a library containing all your URLs.

As an example, consider a blog with a home page and an article page. The article URL has the form /article/1234. We want to show articles without reloading the page.


On the browser, there is a Router class that associates UrlPatterns to handlers. Given a URL, the router finds a pattern that matches, and invokes its handler. The handlers are then responsible for rendering the appropriate changes to the page.

Change Log for m4d_router

A browser routing library for Dart



  • Link to autogenerated example b105179

v0.2 - 2018-06-27


  • deploy-sample.sh failed on Linux 3a9c29e
  • deploy-sample.sh failed on Linux 456927c
  • Jenkins could not find 'deploy-sample'-script - (plural) 63c4187
  • Jenkins could not find 'deploy-samples'-script - extension missing 2dc1317
  • In Dart 2.x List converts to JSArray, changed List to generic List<String> aaca0d7



This CHANGELOG.md was generated with Changelog for Dart

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  m4d_router: ^0.2.5

2. Install it

You can install packages from the command line:

with pub:

$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:m4d_router/browser.dart';
import 'package:m4d_router/exceptions.dart';
import 'package:m4d_router/exeptions/RouteNotFoundException.dart';
import 'package:m4d_router/route.dart';
import 'package:m4d_router/router.dart';
import 'package:m4d_router/url_pattern.dart';
import 'package:m4d_router/utils/async_utils.dart';
import 'package:m4d_router/utils/map_utils.dart';
Version Uploaded Documentation Archive
0.2.5 Jun 29, 2018 Go to the documentation of m4d_router 0.2.5 Download m4d_router 0.2.5 archive
0.2.0 Jun 27, 2018 Go to the documentation of m4d_router 0.2.0 Download m4d_router 0.2.0 archive
0.1.10 Jun 26, 2018 Go to the documentation of m4d_router 0.1.10 Download m4d_router 0.1.10 archive
0.1.6 Jun 25, 2018 Go to the documentation of m4d_router 0.1.6 Download m4d_router 0.1.6 archive
0.1.2 Jun 25, 2018 Go to the documentation of m4d_router 0.1.2 Download m4d_router 0.1.2 archive
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Jul 20, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0-dev.69.0
  • pana: 0.11.7


Detected platforms: web

Platform components identified in package: html.

Issues and suggestions

Support Dart 2 in pubspec.yaml.

The SDK constraint in pubspec.yaml doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see https://www.dartlang.org/dart-2#migration.

The description is too short.

Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

Package is pre-v1 release.

While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction of the API.

Format lib/browser.dart.

Run dartfmt to format lib/browser.dart.

Format lib/exceptions.dart.

Run dartfmt to format lib/exceptions.dart.

Maintain an example.

None of the files in your example/ directory matches a known example patterns. Common file name patterns include: main.dart, example.dart or you could also use m4d_router.dart.

Fix additional 6 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/exeptions/RouteNotFoundException.dart (Run dartfmt to format lib/exeptions/RouteNotFoundException.dart.)
  • lib/route.dart (Run dartfmt to format lib/route.dart.)
  • lib/router.dart (Run dartfmt to format lib/router.dart.)
  • lib/url_pattern.dart (Run dartfmt to format lib/url_pattern.dart.)
  • lib/utils/async_utils.dart (Run dartfmt to format lib/utils/async_utils.dart.)
  • lib/utils/map_utils.dart (Run dartfmt to format lib/utils/map_utils.dart.)


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.8.0 <2.0.0
logging >=0.11.3 <1.0.0 0.11.3+2
uri ^0.11.0 0.11.3
validate ^1.0.0 1.6.0
Transitive dependencies
browser 0.10.0+3
dart2_constant 1.0.1+dart2
intl 0.15.7
logging_handlers 0.8.0
matcher 0.12.4
meta 1.1.6
quiver 0.29.0+2 2.0.0+1
stack_trace 1.9.3
utf 0.9.0+5
Dev dependencies
build_runner any
build_test any
build_web_compilers any
console_log_handler ^1.0.0
mockito any
path ^1.6.0 1.6.2
test ^1.0.0