1e41f4b71Sopenharmony_ci# Defining Page Routes
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciAn application generally consists of more than one page. For example, a music application may come with a music list page and a playback page. You need to link these pages through the page router to implement redirection as required. For example, in a music application, a user taps a song on a music list page to jump to the playback page of the song.
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci
6e41f4b71Sopenharmony_ciThe page router finds the target page based on the page URI. The following describes how to implement redirection between two pages:
7e41f4b71Sopenharmony_ci
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci1. In the **Project** window of DevEco Studio, choose **src** > **main** > **js** > **MainAbility**. Right-click the **pages** folder and choose **NewJS Page** from the shortcut menu to create the **detail** page.
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ci2. Call **router.push()** to navigate users to the **detail** page.
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ci3. Call **router.back()** to navigate users to the **index** page.
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ci
16e41f4b71Sopenharmony_ci## Building the Page Layout
17e41f4b71Sopenharmony_ci
18e41f4b71Sopenharmony_ciThe **index** and **detail** pages each contains a **\<text>** component that specifies the current page, and a **\<button>** component that implements the switching between two pages. Example code in **.hml** files is as follows:
19e41f4b71Sopenharmony_ci
20e41f4b71Sopenharmony_ci```html
21e41f4b71Sopenharmony_ci<!-- index.hml -->
22e41f4b71Sopenharmony_ci<div class="container">
23e41f4b71Sopenharmony_ci  <text class="title">This is the index page.</text>
24e41f4b71Sopenharmony_ci  <button type="capsule" value="Go to the second page" class="button" onclick="launch"></button>
25e41f4b71Sopenharmony_ci</div>
26e41f4b71Sopenharmony_ci```
27e41f4b71Sopenharmony_ci
28e41f4b71Sopenharmony_ci```html
29e41f4b71Sopenharmony_ci<!-- detail.hml -->
30e41f4b71Sopenharmony_ci<div class="container">
31e41f4b71Sopenharmony_ci  <text class="title">This is the detail page.</text>
32e41f4b71Sopenharmony_ci  <button type="capsule" value="Go back" class="button" onclick="launch"></button>
33e41f4b71Sopenharmony_ci</div>
34e41f4b71Sopenharmony_ci```
35e41f4b71Sopenharmony_ci
36e41f4b71Sopenharmony_ci
37e41f4b71Sopenharmony_ci## Setting Page Styles
38e41f4b71Sopenharmony_ci
39e41f4b71Sopenharmony_ciSet styles for the **index** and **detail** pages. Center the **\<text>** and **\<button>** components and space the two components with 50 pixels. The CSS code for the two pages is as follows:
40e41f4b71Sopenharmony_ci
41e41f4b71Sopenharmony_ci```css
42e41f4b71Sopenharmony_ci/* index.css */
43e41f4b71Sopenharmony_ci/* detail.css */
44e41f4b71Sopenharmony_ci.container {
45e41f4b71Sopenharmony_ci  width: 100%;
46e41f4b71Sopenharmony_ci  height: 100%;
47e41f4b71Sopenharmony_ci  flex-direction: column;
48e41f4b71Sopenharmony_ci  justify-content: center;
49e41f4b71Sopenharmony_ci  align-items: center;
50e41f4b71Sopenharmony_ci}
51e41f4b71Sopenharmony_ci
52e41f4b71Sopenharmony_ci.title {
53e41f4b71Sopenharmony_ci  font-size: 50px;
54e41f4b71Sopenharmony_ci  margin-bottom: 50px;
55e41f4b71Sopenharmony_ci}
56e41f4b71Sopenharmony_ci```
57e41f4b71Sopenharmony_ci
58e41f4b71Sopenharmony_ci
59e41f4b71Sopenharmony_ci## Implementing Redirection
60e41f4b71Sopenharmony_ci
61e41f4b71Sopenharmony_ciTo make the **launch** method of the **\<button>** component take effect, the redirection logic needs to be implemented in the **.js** file of the page. Call **router.push()** to add the page URI to the route stack, that is, to jump to the page specified by the URI. You need to import the **router** module before calling the **router** method. The sample code is as follows:
62e41f4b71Sopenharmony_ci
63e41f4b71Sopenharmony_ci```js
64e41f4b71Sopenharmony_ci// index.js
65e41f4b71Sopenharmony_ciimport router from '@ohos.router';
66e41f4b71Sopenharmony_ciexport default {
67e41f4b71Sopenharmony_ci  launch() {
68e41f4b71Sopenharmony_ci    router.push ({
69e41f4b71Sopenharmony_ci      url: 'pages/detail/detail',
70e41f4b71Sopenharmony_ci    });
71e41f4b71Sopenharmony_ci  },
72e41f4b71Sopenharmony_ci}
73e41f4b71Sopenharmony_ci```
74e41f4b71Sopenharmony_ci
75e41f4b71Sopenharmony_ci```js
76e41f4b71Sopenharmony_ci// detail.js
77e41f4b71Sopenharmony_ciimport router from '@ohos.router';
78e41f4b71Sopenharmony_ciexport default {
79e41f4b71Sopenharmony_ci  launch() {
80e41f4b71Sopenharmony_ci    router.back();
81e41f4b71Sopenharmony_ci  },
82e41f4b71Sopenharmony_ci}
83e41f4b71Sopenharmony_ci```
84e41f4b71Sopenharmony_ci
85e41f4b71Sopenharmony_ciThe figure below shows the effect.
86e41f4b71Sopenharmony_ci
87e41f4b71Sopenharmony_ci![en-us_image_0000001222967784](figures/en-us_image_0000001222967784.png)
88