跳到主要内容
版本:v8

ion-nav

shadow

Nav 是一个独立组件,用于加载任意组件并将新组件推入堆栈。

与 Router Outlet 不同,Nav 不绑定到特定的路由器。这意味着如果我们加载一个 Nav 组件并将其他组件推入堆栈,它们不会影响应用的整个路由器。例如,您不应将新组件推入 ion-nav 并期望 URL 更新。这适用于某些用例,例如模态框需要自己的子导航,而不必与应用的 URL 绑定。

备注

ion-nav 不用于路由。相反,请参阅 AngularReactVue 的路由指南,或纯 JavaScript 项目的 ion-router

NavLink 是与 Nav 交互时的简化 API。开发者可以自定义组件、传递组件属性、修改路由动画的方向或定义在导航时的自定义动画。

在模态框内导航

Modal 可以使用 Nav 来提供独立于 URL 的线性导航。

备注

下面的示例使用 Nav 的引用和公共方法 API 来推入和弹出视图。在不需要这种级别的精细访问和控制的实现中,建议使用 NavLink。

接口

虽然不是必需的,但此接口可以替代 CustomEvent 接口,为此组件发出的 Ionic 事件提供更强的类型支持。

interface NavCustomEvent extends CustomEvent {
target: HTMLIonNavElement;
}

属性

animated

说明If true, the nav should animate the transition of components.
属性animated
类型boolean
默认值true

animation

说明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.
属性undefined
类型((baseEl: any, opts?: any) => Animation) | undefined
默认值undefined

root

说明Root NavComponent to load
属性root
类型Function | HTMLElement | ViewController | null | string | undefined
默认值undefined

rootParams

说明Any parameters for the root component
属性undefined
类型T | undefined
默认值undefined

swipeGesture

说明If the nav component should allow for swipe-to-go-back.
属性swipe-gesture
类型boolean | undefined
默认值undefined

事件

Name说明冒泡
ionNavDidChangeEvent fired when the nav has changed componentsfalse
ionNavWillChangeEvent fired when the nav will change componentsfalse

方法

canGoBack

说明Returns true if the current view can go back.
签名canGoBack(view?: ViewController) => Promise<boolean>
参数view: The view to check.

getActive

说明Get the active view.
签名getActive() => Promise<ViewController | undefined>

getByIndex

说明Get the view at the specified index.
签名getByIndex(index: number) => Promise<ViewController | undefined>
参数index: The index of the view.

getLength

说明Returns the number of views in the stack.
签名getLength() => Promise<number>

getPrevious

说明Get the previous view.
签名getPrevious(view?: ViewController) => Promise<ViewController | undefined>
参数view: The view to get.

insert

说明Inserts a component into the navigation stack at the specified index. This is useful to add a component at any point in the navigation stack.
签名insert<T extends NavComponent>(insertIndex: number, component: T, componentProps?: ComponentProps<T> | null, opts?: NavOptions | null, done?: TransitionDoneFn) => Promise<boolean>
参数insertIndex: The index to insert the component at in the stack.
component: The component to insert into the navigation stack.
componentProps: Any properties of the component.
opts: The navigation options.
done: The transition complete function.

insertPages

说明Inserts an array of components into the navigation stack at the specified index. The last component in the array will become instantiated as a view, and animate in to become the active view.
签名insertPages(insertIndex: number, insertComponents: NavComponent[] | NavComponentWithProps[], opts?: NavOptions | null, done?: TransitionDoneFn) => Promise<boolean>
参数insertIndex: The index to insert the components at in the stack.
insertComponents: The components to insert into the navigation stack.
opts: The navigation options.
done: The transition complete function.

pop

说明Pop a component off of the navigation stack. Navigates back from the current component.
签名pop(opts?: NavOptions | null, done?: TransitionDoneFn) => Promise<boolean>
参数opts: The navigation options.
done: The transition complete function.

popTo

说明Pop to a specific index in the navigation stack.
签名popTo(indexOrViewCtrl: number | ViewController, opts?: NavOptions | null, done?: TransitionDoneFn) => Promise<boolean>
参数indexOrViewCtrl: The index or view controller to pop to.
opts: The navigation options.
done: The transition complete function.

popToRoot

说明Navigate back to the root of the stack, no matter how far back that is.
签名popToRoot(opts?: NavOptions | null, done?: TransitionDoneFn) => Promise<boolean>
参数opts: The navigation options.
done: The transition complete function.

push

说明Push a new component onto the current navigation stack. Pass any additional information along as an object. This additional information is accessible through NavParams.
签名push<T extends NavComponent>(component: T, componentProps?: ComponentProps<T> | null, opts?: NavOptions | null, done?: TransitionDoneFn) => Promise<boolean>
参数component: The component to push onto the navigation stack.
componentProps: Any properties of the component.
opts: The navigation options.
done: The transition complete function.

removeIndex

说明Removes a component from the navigation stack at the specified index.
签名removeIndex(startIndex: number, removeCount?: number, opts?: NavOptions | null, done?: TransitionDoneFn) => Promise<boolean>
参数startIndex: The number to begin removal at.
removeCount: The number of components to remove.
opts: The navigation options.
done: The transition complete function.

setPages

说明Set the views of the current navigation stack and navigate to the last view. By default animations are disabled, but they can be enabled by passing options to the navigation controller. Navigation parameters can also be passed to the individual pages in the array.
签名setPages(views: NavComponent[] | NavComponentWithProps[], opts?: NavOptions | null, done?: TransitionDoneFn) => Promise<boolean>
参数views: The list of views to set as the navigation stack.
opts: The navigation options.
done: The transition complete function.

setRoot

说明Set the root for the current navigation stack to a component.
签名setRoot<T extends NavComponent>(component: T, componentProps?: ComponentProps<T> | null, opts?: NavOptions | null, done?: TransitionDoneFn) => Promise<boolean>
参数component: The component to set as the root of the navigation stack.
componentProps: Any properties of the component.
opts: The navigation options.
done: The transition complete function.

CSS Shadow Parts

该组件没有可用的 CSS 阴影部分。

CSS 自定义属性

该组件没有可用的 CSS 自定义属性。

插槽

该组件没有可用的插槽。