routingkit 1.0.0 copy "routingkit: ^1.0.0" to clipboard
routingkit: ^1.0.0 copied to clipboard

Routing Kit - router abstractions and built-in high-performance Radix-Trie router driver.

RoutingKit

Pub Version Test License Sponsors X (formerly Twitter) Follow

Routing Kit - router abstractions and built-in high-performance Radix-Trie router driver.

  • High-performance:Based on Radix Tree implementation, efficient performance.
  • Accurate:Using / to split trie-node nodes can accurately match routes.
  • Flexible:Support dynamic routing matching

Installation #

Add the dependency to your pubspec.yaml file:

dependencies:
  routingkit: ^1.0.0

Or install it with pub:

dart pub add routingkit
# or
flutter pub add routingkit

RoutingKit is an open source project based on the MIT license. If your Router implementation uses RoutingKit, or you find my work helpful to you, please sponsor me on GitHub Sponsors. Your support is my biggest motivation.

Getting Started #

RoutingKit improves the performance of route matching and provides a simpler API. Here is a simple example:

import 'package:routingkit/routingkit.dart';

void main() {
    final router = createRouter(routes: {
        '/users/:name': 0,
    });

    final (params, value) = router.lookup('/users/seven');
    print('User name: ${params('name')}'); // seven
    print('Matched user value: $value'); // 0
}

Create a router instance and register routes #

final router = createRouter();

router.register('/path', 'static route'); // matches `/path`
router.register('/path/:name', 'named route'); // matches `/path/:name<any>`
router.register('/path/foo/*', 'unnamed route'); // matches `/path/foo/<any>`
router.register('/path/bar/**', 'catchall route'); // matches `/path/bar/<any>`

Route Path Segment #

  • <segment>: Constant segment, for example foo only match foo string.
  • :name: Param named segment, define a param name, match and store to Params.
  • *: Unnamed segment, Similar to route naming segemnt, but does not store parameters in Params.
  • **: Catchall segment, any segments are matched.

The Router Methods #

`router.lookup(Srring path) #

Returns a (Params, T?) record, where Params stores all matched parameters and T? store value. If T is null, it means no correct match.

router.register(String route, T value) #

Register a route and store a value.

router.remove(String route) #

Remove a registered route.

License #

RoutingKit is open-sourced software licensed under the MIT license.

3
likes
0
pub points
26%
popularity

Publisher

verified publisherodroe.dev

Routing Kit - router abstractions and built-in high-performance Radix-Trie router driver.

Repository (GitHub)
View/report issues

Topics

#router #routing #routing-kit #radix #radix-router

Funding

Consider supporting this project:

github.com

License

unknown (license)

More

Packages that depend on routingkit