ion-nav
Nav is a standalone component for loading arbitrary components and pushing new components on to the stack.
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 is not meant to be used for routing. Instead, see the routing guides for Angular, React, and Vue, or ion-router for vanilla JavaScript projects.
Using NavLinkβ
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 can use Nav to offer a linear navigation that is independent of the URL.
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β
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 | undefined ο½ { [key: string]: any; } |
| Default | undefined |
swipeGestureβ
| Description | If the nav component should allow for swipe-to-go-back. |
| Attribute | swipe-gesture |
| Type | boolean ο½ undefined |
| Default | undefined |
Eventsβ
| Name | Description | Bubbles |
|---|---|---|
ionNavDidChange | Event fired when the nav has changed components | false |
ionNavWillChange | Event fired when the nav will change components | false |
Methodsβ
canGoBackβ
| Description | Returns true if the current view can go back. |
| Signature | canGoBack(view?: ViewController) => Promise<boolean> |
| Parameters | view: The view to check. |
getActiveβ
| Description | Get the active view. |
| Signature | getActive() => Promise<ViewController ο½ undefined> |
getByIndexβ
| Description | Get the view at the specified index. |
| Signature | getByIndex(index: number) => Promise<ViewController ο½ undefined> |
| Parameters | index: The index of the view. |
getLengthβ
| Description | Returns the number of views in the stack. |
| Signature | getLength() => Promise<number> |
getPreviousβ
| Description | Get the previous view. |
| Signature | getPrevious(view?: ViewController) => Promise<ViewController ο½ undefined> |
| Parameters | view: The view to get. |
insertβ
| Description | 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. |
| Signature | insert<T extends NavComponent>(insertIndex: number, component: T, componentProps?: ComponentProps<T> ο½ null, opts?: NavOptions ο½ null, done?: TransitionDoneFn) => Promise<boolean> |
| Parameters | 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β
| Description | 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. |
| Signature | insertPages(insertIndex: number, insertComponents: NavComponent[] ο½ NavComponentWithProps[], opts?: NavOptions ο½ null, done?: TransitionDoneFn) => Promise<boolean> |
| Parameters | 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β
| Description | Pop a component off of the navigation stack. Navigates back from the current component. |
| Signature | pop(opts?: NavOptions ο½ null, done?: TransitionDoneFn) => Promise<boolean> |
| Parameters | opts: The navigation options. done: The transition complete function. |
popToβ
| Description | Pop to a specific index in the navigation stack. |
| Signature | popTo(indexOrViewCtrl: number ο½ ViewController, opts?: NavOptions ο½ null, done?: TransitionDoneFn) => Promise<boolean> |
| Parameters | indexOrViewCtrl: The index or view controller to pop to. opts: The navigation options. done: The transition complete function. |
popToRootβ
| Description | Navigate back to the root of the stack, no matter how far back that is. |
| Signature | popToRoot(opts?: NavOptions ο½ null, done?: TransitionDoneFn) => Promise<boolean> |
| Parameters | opts: The navigation options. done: The transition complete function. |
pushβ
| Description | Push a new component onto the current navigation stack. Pass any additional information along as an object. This additional information is accessible through NavParams. |
| Signature | push<T extends NavComponent>(component: T, componentProps?: ComponentProps<T> ο½ null, opts?: NavOptions ο½ null, done?: TransitionDoneFn) => Promise<boolean> |
| Parameters | 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β
| Description | Removes a component from the navigation stack at the specified index. |
| Signature | removeIndex(startIndex: number, removeCount?: number, opts?: NavOptions ο½ null, done?: TransitionDoneFn) => Promise<boolean> |
| Parameters | startIndex: The number to begin removal at. removeCount: The number of components to remove. opts: The navigation options. done: The transition complete function. |
setPagesβ
| Description | 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. |
| Signature | setPages(views: NavComponent[] ο½ NavComponentWithProps[], opts?: NavOptions ο½ null, done?: TransitionDoneFn) => Promise<boolean> |
| Parameters | views: The list of views to set as the navigation stack. opts: The navigation options. done: The transition complete function. |
setRootβ
| Description | Set the root for the current navigation stack to a component. |
| Signature | setRoot<T extends NavComponent>(component: T, componentProps?: ComponentProps<T> ο½ null, opts?: NavOptions ο½ null, done?: TransitionDoneFn) => Promise<boolean> |
| Parameters | 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β
No CSS shadow parts available for this component.
CSS Custom Propertiesβ
No CSS custom properties available for this component.
Slotsβ
No slots available for this component.