path property

String path
finalinherited

The path of this go route.

For example:

GoRoute(
  path: '/',
  pageBuilder: (BuildContext context, GoRouterState state) => MaterialPage<void>(
    key: state.pageKey,
    child: HomePage(families: Families.data),
  ),
),

The path also support path parameters. For a path: /family/:fid, it matches all URIs start with /family/..., e.g. /family/123, /family/456 and etc. The parameter values are stored in GoRouterState that are passed into pageBuilder and builder.

A path parameter may optionally be constrained to a regular expression by appending the expression in parentheses after the parameter name: :paramName(regex).

// Copyright 2013 The Flutter Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';

/// Router configuration demonstrating regex-constrained path parameters.
final GoRouter router = GoRouter(
  routes: <GoRoute>[
    GoRoute(
      path: r'/users/:id(\d+)',
      builder: (BuildContext context, GoRouterState state) {
        return Scaffold(body: Center(child: Text('User ${state.pathParameters['id']}')));
      },
    ),
  ],
);

/// Runs the path parameter regular expression example.
void main() {
  runApp(const PathParameterRegexApp());
}

/// A minimal app demonstrating regex-constrained path parameters.
class PathParameterRegexApp extends StatelessWidget {
  /// Creates a [PathParameterRegexApp].
  const PathParameterRegexApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp.router(routerConfig: router);
  }
}

The path matches /users/42 but not /users/settings. If a path segment does not satisfy the regular expression, route matching continues with other route candidates.

The regular expression is interpreted as a Dart RegExp pattern and must not contain nested parentheses.

The query parameter are also capture during the route parsing and stored in GoRouterState.

See Query parameters and path parameters to learn more about parameters.

Implementation

final String path;