UNPKG

8.72 kBJavaScriptView Raw
1/**
2 * \@name IonicPage
3 * \@description
4 * The Ionic Page handles registering and displaying specific pages based on URLs. It's used
5 * underneath `NavController` so it will never have to be interacted with directly. When a new
6 * page is pushed with `NavController`, the URL is updated to match the path to this page.
7 *
8 * Unlike traditional web apps, URLs don't dictate navigation in Ionic apps.
9 * Instead, URLs help us link to specific pieces of content as a breadcrumb.
10 * The current URL gets updated as we navigate, but we use the `NavController`
11 * push and pop, or `NavPush` and `NavPop` to move around. This makes it much easier
12 * to handle complicated nested navigation.
13 *
14 * We refer to our URL system as a deep link system instead of a router to encourage
15 * Ionic developers to think of URLs as a breadcrumb rather than as the source of
16 * truth in navigation. This encourages flexible navigation design and happy apps all
17 * over the world.
18 *
19 *
20 * \@usage
21 *
22 * The first step to setting up deep links is to add the page that should be
23 * a deep link in the `IonicPageModule.forChild` import of the page's module.
24 * For our examples, this will be `MyPage`:
25 *
26 * ```ts
27 * \@NgModule({
28 * declarations: [
29 * MyPage
30 * ],
31 * imports: [
32 * IonicPageModule.forChild(MyPage)
33 * ],
34 * entryComponents: [
35 * MyPage
36 * ]
37 * })
38 * export class MyPageModule {}
39 * ```
40 *
41 * Then, add the `\@IonicPage` decorator to the component. The most simple usage is adding an
42 * empty decorator:
43 *
44 * ```ts
45 * \@IonicPage()
46 * \@Component({
47 * templateUrl: 'main.html'
48 * })
49 * export class MyPage {}
50 * ```
51 *
52 * This will automatically create a link to the `MyPage` component using the same name as the class,
53 * `name`: `'MyPage'`. The page can now be navigated to by using this name. For example:
54 *
55 * ```ts
56 * \@Component({
57 * templateUrl: 'another-page.html'
58 * })
59 * export class AnotherPage {
60 * constructor(public navCtrl: NavController) {}
61 *
62 * goToMyPage() {
63 * // go to the MyPage component
64 * this.navCtrl.push('MyPage');
65 * }
66 * }
67 * ```
68 *
69 * The `\@IonicPage` decorator accepts a `DeepLinkMetadataType` object. This object accepts
70 * the following properties: `name`, `segment`, `defaultHistory`, and `priority`. All of them
71 * are optional but can be used to create complex navigation links.
72 *
73 *
74 * ### Changing Name
75 *
76 * As mentioned previously, the `name` property will be set to the class name if it isn't provided.
77 * Changing the name of the link is extremely simple. To change the name used to link to the
78 * component, simply pass it in the decorator like so:
79 *
80 * ```ts
81 * \@IonicPage({
82 * name: 'my-page'
83 * })
84 * ```
85 *
86 * This will create a link to the `MyPage` component using the name `'my-page'`. Similar to the previous
87 * example, the page can be navigated to by using the name:
88 *
89 * ```ts
90 * goToMyPage() {
91 * // go to the MyPage component
92 * this.navCtrl.push('my-page');
93 * }
94 * ```
95 *
96 *
97 * ### Setting URL Path
98 *
99 * The `segment` property is used to set the URL to the page. If this property isn't provided, the
100 * `segment` will use the value of `name`. Since components can be loaded anywhere in the app, the
101 * `segment` doesn't require a full URL path. When a page becomes the active page, the `segment` is
102 * appended to the URL.
103 *
104 * The `segment` can be changed to anything and doesn't have to match the `name`. For example, passing
105 * a value for `name` and `segment`:
106 *
107 * ```ts
108 * \@IonicPage({
109 * name: 'my-page',
110 * segment: 'some-path'
111 * })
112 * ```
113 *
114 * When navigating to this page as the first page in the app, the URL will look something like:
115 *
116 * ```
117 * http://localhost:8101/#/some-path
118 * ```
119 *
120 * However, navigating to the page will still use the `name` like the previous examples do.
121 *
122 *
123 * ### Dynamic Links
124 *
125 * The `segment` property is useful for creating dynamic links. Sometimes the URL isn't known ahead
126 * of time, so it can be passed as a variable.
127 *
128 * Since passing data around is common practice in an app, it can be reflected in the app's URL by
129 * using the `:param` syntax. For example, set the `segment` in the `\@IonicPage` decorator:
130 *
131 * ```ts
132 * \@IonicPage({
133 * name: 'detail-page',
134 * segment: 'detail/:id'
135 * })
136 * ```
137 *
138 * In this case, when we `push` to a new instance of `'detail-page'`, the value of `id` will
139 * in the `detailInfo` data being passed to `push` will replace `:id` in the URL.
140 *
141 * Important: The property needs to be something that can be converted into a string, objects
142 * are not supported.
143 *
144 * For example, to push the `'detail-page'` in the `ListPage` component, the following code could
145 * be used:
146 *
147 * ```ts
148 * \@IonicPage({
149 * name: 'list'
150 * })
151 * export class ListPage {
152 * constructor(public navCtrl: NavController) {}
153 *
154 * pushPage(detailInfo) {
155 * // Push an `id` to the `'detail-page'`
156 * this.navCtrl.push('detail-page', {
157 * 'id': detailInfo.id
158 * })
159 * }
160 * }
161 * ```
162 *
163 * If the value of `detailInfo.id` is `12`, for example, the URL would end up looking like this:
164 *
165 * ```
166 * http://localhost:8101/#/list/detail/12
167 * ```
168 *
169 * Since this `id` will be used to pull in the data of the specific detail page, it's Important
170 * that the `id` is unique.
171 *
172 * Note: Even though the `name` is `detail-page`, the `segment` uses `detail/:id`, and the URL
173 * will use the `segment`.
174 *
175 *
176 * ### Default History
177 *
178 * Pages can be navigated to using deep links from anywhere in the app, but sometimes the app is
179 * launched from a URL and the page needs to have the same history as if it were navigated to from
180 * inside of the app.
181 *
182 * By default, the page would be navigated to as the first page in the stack with no prior history.
183 * A good example is the App Store on iOS. Clicking on a URL to an application in the App Store will
184 * load the details of the application with no back button, as if it were the first page ever viewed.
185 *
186 * The default history of any page can be set in the `defaultHistory` property. This history will only
187 * be used if the history doesn't already exist, meaning if you navigate to the page the history will
188 * be the pages that were navigated from.
189 *
190 * The `defaultHistory` property takes an array of strings. For example, setting the history of the
191 * detail page to the list page where the `name` is `list`:
192 *
193 * ```ts
194 * \@IonicPage({
195 * name: 'detail-page',
196 * segment: 'detail/:id',
197 * defaultHistory: ['list']
198 * })
199 * ```
200 *
201 * In this example, if the app is launched at `http://localhost:8101/#/detail/my-detail` the displayed page
202 * will be the `'detail-page'` with an id of `my-detail` and it will show a back button that goes back to
203 * the `'list'` page.
204 *
205 * An example of an application with a set history stack is the Instagram application. Opening a link
206 * to an image on Instagram will show the details for that image with a back button to the user's profile
207 * page. There is no "right" way of setting the history for a page, it is up to the application.
208 *
209 * ### Priority
210 *
211 * The `priority` property is only used during preloading. By default, preloading is turned off so setting
212 * this property would do nothing. Preloading eagerly loads all deep links after the application boots
213 * instead of on demand as needed. To enable preloading, set `preloadModules` in the main application module
214 * config to `true`:
215 *
216 * ```ts
217 * \@NgModule({
218 * declarations: [
219 * MyApp
220 * ],
221 * imports: [
222 * BrowserModule,
223 * IonicModule.forRoot(MyApp, {
224 * preloadModules: true
225 * })
226 * ],
227 * bootstrap: [IonicApp],
228 * entryComponents: [
229 * MyApp
230 * ]
231 * })
232 * export class AppModule { }
233 * ```
234 *
235 * If preloading is turned on, it will load the modules based on the value of `priority`. The following
236 * values are possible for `priority`: `"high"`, `"low"`, and `"off"`. When there is no `priority`, it
237 * will be set to `"low"`.
238 *
239 * All deep links with their priority set to `"high"` will be loaded first. Upon completion of loading the
240 * `"high"` priority modules, all deep links with a priority of `"low"` (or no priority) will be loaded. If
241 * the priority is set to `"off"` the link will not be preloaded. Setting the `priority` is as simple as
242 * passing it to the `\@IonicPage` decorator:
243 *
244 * ```ts
245 * \@IonicPage({
246 * name: 'my-page',
247 * priority: 'high'
248 * })
249 * ```
250 *
251 * We recommend setting the `priority` to `"high"` on the pages that will be viewed first when launching
252 * the application.
253 *
254 * @param {?=} _config
255 * @return {?}
256 */
257export function IonicPage(_config) {
258 return function (clazz) {
259 return clazz;
260 };
261}
262//# sourceMappingURL=ionic-page.js.map
\No newline at end of file