browser_routes

Creator: coderz1093

Last updated:

0 purchases

browser_routes Image
browser_routes Images

Languages

Categories

Add to Cart

Description:

browser routes

In-browser routing for simple dart-driven single page applications (SPA). Support for:

plain urls: /my/example/page
named path variable: /hello/:name
optionally named path variables: /hello/:name/:?andGuest
path with wildcards: /api/* to allow for dynamic content or route to a subsystem

Incoming URL's are compared by segment length first. Route definitions with equal length are resolved in the order as defined above.
Usage #
Set up a simple dart web app:
stagehand web-simple
copied to clipboard
Edit pubspec.yaml:
dependencies:
browser_routes: ^1.0.0
copied to clipboard
Edit web/main.dart:
import 'package:browser_routes/browser_routes.dart';

bool authOk(void Function() f) {
f();
return true;
}

void main() {
final router = HashRouter(onError: (Url url) =>
authOk(() => print('${url.code}: $url'))
);
final hello_route = router.register('hello/:name', 'Hello World', (Url url) =>
authOk(() => print("hello '${url.params['name']}'"))
);
final home_route = router.register('/', 'Home', (Url url) =>
authOk(() => print('home screen'))
);

hello_route.navigateTo(params: {'name': 'Peter'});
}
copied to clipboard
webdev serve
copied to clipboard
Navigate to localhost:8080/#/hello/Brian
Path's without # #
When using Router() instead of HastRouter() configure your webserver to serve index.html for all paths.
Nginx-sample:
location / {
try_files $uri $uri/ /index.html;
}
copied to clipboard
Testing #
pub run test -p chrome test/browser_routes_test.dart
pub run test -p chrome test/browser_routes_test_async.dart
copied to clipboard
Features and bugs #
Please file feature requests and bugs at the issue tracker.

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.