ion-nav
Nav 是一个独立组件,用于加载任意组件并将新组件推送到堆栈上。
🌐 Nav is a standalone component for loading arbitrary components and pushing new components on to the stack.
与路由出口不同,Nav 不与特定路由绑定。这意味着如果我们加载一个 Nav 组件,并将其他组件推入栈中,它们不会影响应用的整体路由。例如,你不应该向 ion-nav 推送一个新组件并期望 URL 会更新。这适用于一些使用场景,比如你可能有一个模态窗口,它需要自己的子导航,而不将其绑定到应用的 URL。
🌐 Unlike Router Outlet, Nav is not tied to a particular router. This means that if we load a Nav component, and push other components to the stack, they will not affect the app's overall router. For example, you should not push a new component to ion-nav and expect the URL to update. This fits use cases where you could have a modal, which needs its own sub-navigation, without making it tied to the apps URL.
ion-nav 并不是用来做路由的。相反,请参阅 Angular、React 和 Vue 的路由指南,或用于原生 JavaScript 项目的 ion-router。
使用导航链接
🌐 Using NavLink
NavLink 是与 Nav 交互时的简化 API。开发者可以自定义组件,传递组件属性,修改路由动画的方向,或在导航时定义自定义动画。
🌐 NavLink is a simplified API when interacting with Nav. Developers can customize the component, pass along component properties, modify the direction of the route animation or define a custom animation when navigating.
模态框内的导航
🌐 Navigation within a Modal
Modal 可以使用 Nav 提供独立于 URL 的线性导航。
🌐 Modal can use Nav to offer a linear navigation that is independent of the URL.
下面的示例使用对 Nav 的引用和公共方法 API 来推送和弹出视图。建议在不需要这种粒度访问和控制的实现中使用 NavLink。
🌐 The example below uses a reference to Nav and the public method APIs to push and pop views. It is recommended to use NavLink in implementations that do not require this level of granular access and control.
接口
🌐 Interfaces
NavCustomEvent
虽然不是必需的,但可以使用此接口替代 CustomEvent 接口,以便对从此组件发出的 Ionic 事件进行更强类型的处理。
🌐 While not required, this interface can be used in place of the CustomEvent interface for stronger typing with Ionic events emitted from this component.
interface NavCustomEvent extends CustomEvent {
target: HTMLIonNavElement;
}
属性
🌐 Properties
animated
| Description | If true, the nav should animate the transition of components. |
| Attribute | animated |
| Type | boolean |
| Default | true |
animation
| Description | By default ion-nav animates transition between pages based in the mode (ios or material design). However, this property allows to create custom transition using AnimationBuilder functions. |
| Attribute | undefined |
| Type | ((baseEl: any, opts?: any) => Animation) | undefined |
| Default | undefined |
root
| Description | Root NavComponent to load |
| Attribute | root |
| Type | Function | HTMLElement | ViewController | null | string | undefined |
| Default | undefined |
rootParams
| Description | Any parameters for the root component |
| Attribute | undefined |
| Type | T | undefined |
| Default | undefined |
swipeGesture
| Description | If the nav component should allow for swipe-to-go-back. |
| Attribute | swipe-gesture |
| Type | boolean | undefined |
| Default | undefined |