blob: e616dc4a68bfcdbf942c48617b72c39f17e501a0 [file] [log] [blame]
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/foundation.dart';
import 'configuration.dart';
/// The route state during routing.
class GoRouterState {
/// Default constructor for creating route state during routing.
this._configuration, {
required this.location,
required this.subloc,
this.params = const <String, String>{},
this.queryParams = const <String, String>{},
ValueKey<String>? pageKey,
}) : pageKey = pageKey ??
ValueKey<String>(error != null
? 'error'
: fullpath != null && fullpath.isNotEmpty
? fullpath
: subloc),
assert((path ?? '').isEmpty == (fullpath ?? '').isEmpty);
// TODO(johnpryan): remove once namedLocation is removed from go_router.
// See
final RouteConfiguration _configuration;
/// The full location of the route, e.g. /family/f2/person/p1
final String location;
/// The location of this sub-route, e.g. /family/f2
final String subloc;
/// The optional name of the route.
final String? name;
/// The path to this sub-route, e.g. family/:fid
final String? path;
/// The full path to this sub-route, e.g. /family/:fid
final String? fullpath;
/// The parameters for this sub-route, e.g. {'fid': 'f2'}
final Map<String, String> params;
/// The query parameters for the location, e.g. {'from': '/family/f2'}
final Map<String, String> queryParams;
/// An extra object to pass along with the navigation.
final Object? extra;
/// The error associated with this sub-route.
final Exception? error;
/// A unique string key for this sub-route, e.g. ValueKey('/family/:fid')
final ValueKey<String> pageKey;
/// Get a location from route name and parameters.
/// This is useful for redirecting to a named location.
// TODO(johnpryan): deprecate namedLocation API
// See
String namedLocation(
String name, {
Map<String, String> params = const <String, String>{},
Map<String, String> queryParams = const <String, String>{},
}) {
return _configuration.namedLocation(name,
params: params, queryParams: queryParams);