You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 22, 2018. It is now read-only.
Route is a client routing library for Dart that helps make buildingsingle-page web apps.
Installation
Add this package to your pubspec.yaml file:
dependencies: route_hierarchical: any
Then, runpub install to download and link in the package.
UrlMatcher
Route is built aroundUrlMatcher, an interface that defines URL templateparsing, matching and reversing.
UrlTemplate
The default implementation of theUrlMatcher isUrlTemplate. As an example,consider a blog with a home page and an article page. The article URL has theform /article/1234. It can matched by the following template:/article/:articleId.
Router
Router is a stateful object that contains routes and can perform URL routingon those routes.
TheRouter can listen toWindow.onPopState (or fallback toWindow.onHashChange in older browsers) events and invoke the correcthandler so that the back button seamlessly works.
Example (client.dart):
library client;import'package:route_hierarchical/client.dart';main() {var router=newRouter(); router.root ..addRoute(name:'article', path:'/article/:articleId', enter: showArticle) ..addRoute(name:'home', defaultRoute:true, path:'/', enter: showHome); router.listen();}voidshowHome(RouteEvent e) {// nothing to parse from path, since there are no groups}voidshowArticle(RouteEvent e) {var articleId= e.parameters['articleId'];// show article page with loading indicator// load article from server, then render article}
The client side router can let you define nested routes.
The mount parameter takes either a function that accepts an instance of a newchild router as the only parameter, or an instance of an object that implementsRoutable interface.
In either case, the child router is instantiated by the parent router aninjected into the mount point, at which point child router can be configuredwith new routes.
Routing with hierarchical router: when the parent router performs a prefixmatch on the URL, it removes the matched part from the URL and invokes thechild router with the remaining tail.
For instance, with the above example lets consider this URL:/user/jsmith/article/1234.Route "user" will match/user/jsmith and invoke the child router with/article/1234.Route "article" will match/article/1234 and invoke the child router with ``.Route "view" will be matched as the default route.The resulting route path will be:user -> article -> view, or simply `user.article.view`