openharmony 鸿蒙 arkts-navigation-introduction

2025-06-12 浏览 (1)

Component Navigation and Page Routing Overview

The Navigation component and the APIs in the Router (@ohos.router) module both facilitate page redirection within an application. Yet, the Navigation component excels by offering intra-component redirection, which is particularly beneficial in one-time development for multi-device deployment. It provides more flexible page stack operations and a wider range of animations and lifecycles. Therefore, to deliver a better user experience, use the Navigation component to implement page redirection and intra-component redirection whenever possible.

Architecture Differences

In the ArkUI component tree hierarchy, pages that were originally managed by the Router module are located beneath the stage management node of the page stack. Navigation, as a navigation container component, can be mounted under a single page node and can also be stacked and nested. Navigation manages the title bar, toolbar, and content area, an area designed to display the content of custom pages and allowing for page routing. The design of Navigation has the following advantages:

image

  1. Explicitly distinguishes the title bar, content area, and toolbar in the API for enhanced management and UX animation flexibility.

  2. Explicitly provides a routing container, allowing you to decide its location, which can be in a modal, sheet, or dialog box.

  3. Integrates UX design and one-time development for multi-device deployment capabilities, with default capabilities for unified title display, page switching, and single or double column adaptation.

  4. Enables flexible page configuration by allowing you to determine the relationship between page aliases and UI through UIBuilder.

  5. Transforms page transition animations into component property animations, offering a wider and more flexible range of transition effects.

  6. Provides an inheritable page stack object for improved page display management.

Capability Comparison

ScenarioNavigationRouter
One-time development for multi-device deploymentSupported. The Auto mode is provided to automatically adapt to single- or double-column layout.Not supported
Navigation to a specific pagepushPath & pushDestinationpushUrl & pushNameRoute
Navigation to a page within an HSPSupportedSupported
Navigation to a page within a HARSupportedSupported
Passing parameters during navigationSupportedSupported
Obtaining parameters of a specific pageSupportedNot supported
Type of parameters passedPassed as an objectPassed as an object, methods not supported within the object
Navigation result callbackSupportedSupported
Navigation to a singleton pageSupportedSupported
Return to a previous pageSupportedSupported
Passing parameters on returning to a previous pageSupportedSupported
Returning to a specific routeSupportedSupported
Dialog box for returning to a previous pageSupported, implemented through route interceptionshowAlertBeforeBackPage
Route replacementreplacePath & replacePathByNamereplaceUrl & replaceNameRoute
Clearing the navigation stackclearclear
Removing specific routes from the navigation stackremoveByIndexes & removeByNameNot supported
Transition animationSupportedSupported
Custom transition animationSupportedSupported, with limited animation types
Disabling transition animationSupported, with global or one-time settingSupported, by setting duration in the pageTransition API to 0
Shared element animation with geometryTransitionSupported (shared between NavDestination components)Not supported
Listening for page lifecycleUIObserver.on('navDestinationUpdate')UIObserver.on('routerPageUpdate')
Obtaining a page stack objectSupportedNot supported
Route interceptionSupported through setInterceptionNot supported
Route stack information querySupportedgetState() & getLength()
Move operations within the navigation stackmoveToTop & moveIndexToTopNot supported
Immersive pagesSupportedNot supported; requires window configuration
Setting the title bar and toolbarSupportedNot supported
Modal nested routingSupportedNot supported

你可能感兴趣的鸿蒙文章

harmony 鸿蒙ArkUI

harmony 鸿蒙Atomic Service Full Screen Launch Component (FullScreenLaunchComponent)

harmony 鸿蒙Arc Button (ArcButton)

harmony 鸿蒙Animation Smoothing

harmony 鸿蒙Animation Overview

harmony 鸿蒙Frame Animation (ohos.animator)

harmony 鸿蒙Implementing Property Animation

harmony 鸿蒙Property Animation Overview

harmony 鸿蒙Dialog Box Overview

harmony 鸿蒙Blur Effect

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/eLM7De