createError property

RouteBuilder<T>? createError
final

If Segment.parse cannot find a matching route the bottom most createError is called instead.

  final router = Segment.root<String>(
    create: (context) => 'rootRoute',
    createError: (context) => 'rootError',
    children: [
      Segment.path(
        name: 'settings',
        create: (context) => 'settingsRoute',
        createError: (context) => 'settingsError',
        children: [
          Segment.path(
            name: 'privacySettings'
            create: (context) => 'privacyRoute',
          ),
        ],
      ),
      Segment.path(
        name: 'user',
        create: (context) => 'userRoute',
      ),
    ],
  );

  assert(router.route(Uri.parse('http://test.com/noRoute')) == 'rootError');
  assert(router.route(Uri.parse('http://test.com/user/noRoute')) == 'rootError');
  assert(router.route(Uri.parse('http://test.com/settings/noRoute')) == 'settingsError');

Implementation

final RouteBuilder<T>? createError;