title |
---|
ion-nav |
import Props from '@ionic-internal/component-api/v8/nav/props.md'; import Events from '@ionic-internal/component-api/v8/nav/events.md'; import Methods from '@ionic-internal/component-api/v8/nav/methods.md'; import Parts from '@ionic-internal/component-api/v8/nav/parts.md'; import CustomProps from '@ionic-internal/component-api/v8/nav/custom-props.mdx'; import Slots from '@ionic-internal/component-api/v8/nav/slots.md';
<title>ion-nav: Nav View Component for Ionic Framework Apps</title>import EncapsulationPill from '@components/page/api/EncapsulationPill';
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.
:::note
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.
:::
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.
import NavLinkExample from '@site/static/usage/v8/nav/nav-link/index.md';
Modal can use Nav to offer a linear navigation that is independent of the URL.
:::note
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.
:::
import ModalNavigationExample from '@site/static/usage/v8/nav/modal-navigation/index.md';
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;
}