toNamed<T> method

Future<T?>? toNamed<T>(
  1. String page, {
  2. dynamic arguments,
  3. dynamic id,
  4. @Deprecated('preventDuplicates 已被弃用, 相关代码被注释掉了, 重复路由的相关逻辑处理放到了 preventDuplicateHandlingMode 中, 请使用 preventDuplicateHandlingMode 来处理') bool preventDuplicates = true,
  5. Map<String, String>? parameters,
})

Navigation.pushNamed() shortcut.

Pushes a new named page to the stack.

It has the advantage of not needing context, so you can call from your business logic.

You can send any type of value to the other route in the arguments.

id is for when you are using nested navigation, as explained in documentation

By default, GetX will prevent you from push a route that you already in, if you want to push anyway, set preventDuplicates to false

Note: Always put a slash on the route ('/page1'), to avoid unexpected errors

Implementation

Future<T?>? toNamed<T>(
  String page, {
  dynamic arguments,
  dynamic id,
  @Deprecated(
      'preventDuplicates 已被弃用, 相关代码被注释掉了, 重复路由的相关逻辑处理放到了 preventDuplicateHandlingMode 中, 请使用 preventDuplicateHandlingMode 来处理')
  bool preventDuplicates = true,
  Map<String, String>? parameters,
}) {
  // if (preventDuplicates && page == currentRoute) {
  //   return null;
  // }

  if (parameters != null) {
    final uri = Uri(path: page, queryParameters: parameters);
    page = uri.toString();
  }

  return searchDelegate(id).toNamed(
    page,
    arguments: arguments,
    id: id,
    preventDuplicates: preventDuplicates,
    parameters: parameters,
  );
}