parse_route 2.1.0 copy "parse_route: ^2.1.0" to clipboard
parse_route: ^2.1.0 copied to clipboard

All-encompassing solution for route parsing, matching, and navigation within Dart applications

example/example.md

Basic Route Registration and Matching #

import 'package:parse_route/parse_route.dart';

void main() {
  final parser = ParseRoute();

  // Register routes
  parser.registerRouter('/user/:id');
  parser.registerRouter('/profile/followers');

  // Match routes
  final result1 = parser.matchRoute('/user/123');
  print(result1?.parameters); // {id: 123}

  final result2 = parser.matchRoute('/profile/followers');
  print(result2?.path); // /profile/followers
}
copied to clipboard
final parser = ParseRoute();

parser.registerRouter('/home');
parser.registerRouter('/profile/:id');

// Navigate to a route
parser.push('/home');

// Navigate with parameters
parser.push('/profile/123');

// Go back
parser.pop();

// Replace current route
parser.replaceLast('/settings');
copied to clipboard

Route Listeners #

parser.addListener('/profile', (newRoute, oldRoute, type) {
  print('Profile route changed: ${newRoute.fullPath}');
});

parser.push('/profile/123'); // Triggers listener
copied to clipboard

Complex Routes #

parser.registerRouter('/project/:projectId/task/:taskId/detail');

final result = parser.matchRoute('/project/42/task/108/detail?foo=bar');
print(result?.parameters); // {projectId: 42, taskId: 108}
print(result?.urlParameters); // {foo: bar}
copied to clipboard

API Reference #

ParseRoute #

  • registerRouter(String path): Register a new route
  • matchRoute(String path): Match a given path to a registered route
  • push(String path): Navigate to a new route
  • pop(): Go back to the previous route
  • replaceLast(String path): Replace the current route
  • addListener(String path, RouteListener listener): Add a listener for route changes
  • removeListener(String path): Remove a route listener

MatchResult #

  • path: The matched route path
  • cleanPath: The actual path without query parameters
  • parameters: Map of route parameters
  • urlParameters: Map of URL query parameters
10
likes
160
points
161
downloads

Publisher

verified publishergetx.site

Weekly Downloads

2024.06.21 - 2025.01.03

All-encompassing solution for route parsing, matching, and navigation within Dart applications

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

More

Packages that depend on parse_route