---
updatedAt: 2025-07-15T09:13:27.000Z
agentTools:
  projectIndex: https://docs.appery.io/llms.txt
---

# Routing

Setting up routing (navigation) for an Ionic app.

# Introduction

One of the core  **AngularJS** features is **Routing**, which is used to build a single page app with multiple views. Using **Routing** to load different parts of the app helps logically divide the app and make it more manageable.

**Routing** is needed to show different content depending on what route is chosen. It sets the page content to be displayed in the **ng-view** component of the **index** page.

# Using Routing

When creating a new page you are suggested to create a navigation route for it:

<Image title="ionic_navigation_create.png" alt={591} src="https://files.readme.io/ff2f734-ionic_navigation_create.png">
  New page with navigation.
</Image>

Once a page is created, go to **Project > Routing** to see the newly created routing:

<Image title="ionic_navigation_routing.png" alt={1177} src="https://files.readme.io/fc736f9-ionic_navigation_routing.png">
  Ionic Routing.
</Image>

It's also simple to add a route manually. On the **Routing** view:

1. Enter the route name.
2. Select the page (where to navigate).
3. Click **Add** to add this routing rule.

Make sure a **Default route** is set. The **Default route** shows the first page that will be shown when the app loads.

Navigating to a non-existing route will also redirect you to a default screen. Several routes can lead to the same screen but paths must be different.

> 🚧 Duplicate Paths
>
> Routing should not contain duplicated paths. Unique paths are recommended to ensure your app works correctly.

When renaming a page, you can choose whether to change paths of the corresponding routes.

<Image title="ionic_rename_page.png" alt={589} src="https://files.readme.io/a64dffb-ionic_rename_page.png">
  Renaming screen and route.
</Image>

You can add a dependency for each route by clicking the **Manage dependencies** button. Note, that you should enable this dependency in the [Dependency Manager](https://docs.appery.io/reference/appbuilder-ionic-dependency-manager) beforehand.

# How Routing Works

To build an app that has multiple views, an AngularJS module called **ngRoute** is used.\
AngularJS uses [$routeProvider](https://docs.angularjs.org/api/ngRoute/provider/$routeProvider) to handle all of the magic required to get a new file and inject it into layout.

**ng-view** is an AngularJS directive that will include the template of the current route (/home, /about, or /contact) in the main layout file. In plain words, it takes the file you want based on the route and injects it into your main layout (index.html). In **Routing**, you set where to place the rendered pages.

> 📘 Further Information
>
> Read more about passing parameters in URL [here](https://docs.angularjs.org/api/ngRoute/provider/$routeProvider).

## Using a Directive to Navigate

Navigating to a page is as simple as using the built-in **navigate-to** directive and setting its value to an existing route:

<Image title="ionic_navigate_function_arguments.png" alt={527} src="https://files.readme.io/647ca3f-ionic_navigate_function_arguments.png">
  Using navigate-to directive.
</Image>

## Using JavaScript API to Navigate

To navigate using JavaScript API, create a **Scope** function called **goToPage()** with the following code:

```javascript Code example
Apperyio.navigateTo("Screen2");
```

> 📘 Inserting Navigation Code With Code Assist
>
> You can insert Apperyio.navigateTo code using a snippet.  Select **Navigate to Page** snippet from the snippets list.

> 📘 Navigate to Route with Drag & Drop
>
> Drag the needed page from **Project tree** and drop it in **Scope**'s function.

For the component which is to invoke the navigation, use the **ng-click** directive and set it to **goToPage()** function (also available via code assist).

## Passing Parameters

In **Routing**, set the parameters to pass. The following examples show passing two parameters:   **userId** and **productId**:

```text Path
/Screen2.html/:userId/:productId
```

This is how it looks in the **Routing** view:

<Image title="ionic_navigation_path_params.png" alt={531} src="https://files.readme.io/46e3384-ionic_navigation_path_params.png">
  Passing parameters in the URL.
</Image>

### Using Directive

Passing parameters using the  special **navigate-to\[name]** directive:

<Image title="ionic_navigation_passing_params_directive_page.png" alt={464} src="https://files.readme.io/cada117-ionic_navigation_passing_params_directive_page.png">
  Passing parameters using the built-in directive.
</Image>

### Using JavaScript API

Passing parameters using the Javascript API, update the **goToPage** function in **Scope**:

```javascript Code example
Apperyio.navigateTo("Screen2", {userId: "84500", productId: "100ABC"});
```

After navigation, you should see the parameters and the updated URL:

```text New URL
http://appery.io/app/view/APP_ID/#/Screen2.html/84500/100ABC
```

> 📘 Changing the URL
>
> To see the changed URL click **Remove frame** button.

### Passing in Runtime

To pass navigation parameters in runtime, you can set **ng-click** to:

```text
goToPage('Screen2', {'userId':'84500', 'productId':'100ABC'});
```

The **goToPage** function in **Scope** is updated with two parameters (**routeName**, **params**) in definition and updated code:

```text
Apperyio.navigateTo(routeName, params);
```

<Image title="ionic_navigate_function_arguments.png" alt={527} src="https://files.readme.io/e0b91ee-ionic_navigate_function_arguments.png">
  Passing navigation parameters in runtime.
</Image>

## Accessing Parameters

On the page where you navigate to, add this code anywhere you need to access the passed parameters:

```javascript
var $routeParams = Apperyio.get( "$routeParams" );
$scope.userId = $routeParams.userId;
$scope.productId = $routeParams.productId;
```

Now **userId** and **productId** can be displayed on a page.

## Converting Route Name to URL

The  **routeName2Url()** function that returns a route path generated from a route name and dynamic parameters:

```javascript Code example
Apperyio.routeName2Url( route_name /*, options*/ );
```

The first parameter is a route name. The second parameter is an object with path variables.

For example, there is a route named **route\_one** that equals to http\://<span></span>somedomain.com/route/path/:id/:value/done/.

The following code will return http\://<span></span>somedomain.com/route/path/10/4/done/:

```javascript Code example
Apperyio.routeName2Url('route_one', {id:10, value:4});
```

## Using Route Path Template

By default route path template looks like **/screen\_name.html**. You can easily change path by clicking the dropdown list and selecting a **new screen**. The default path may be changed this way when needed.

You can manually change a path value, including the default part (for example, you change **/Screen1.html** to **/Screen1**). From now, automatically inserting a new path when selecting from list is disabled. This is to prevent you from changing your custom path occasionally.

![750](https://files.readme.io/R9KOsMYOQmGe68OzbERc_custom.png "custom.png")

However, if you leave the default part (for example, **/screen1.html** or **/screen1.html/some/path/here**) it can be changed as usual.