You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: versioned_docs/version-v5/reference/migration.md
+3-298Lines changed: 3 additions & 298 deletions
Original file line number
Diff line number
Diff line change
@@ -9,303 +9,8 @@ import TabItem from '@theme/TabItem';
9
9
10
10
## Migrating from Ionic 4.x to Ionic 5.x
11
11
12
-
Migrating an app from 4.x to 5.x requires a few updates to the API properties, CSS utilities, and the installed package dependencies.
12
+
Please see the [Ionic 5 Migration Guide](/docs/updating/5-0).
13
13
14
-
### API and CSS Updates
14
+
##Migrating to Ionic 4.0
15
15
16
-
For a complete list of breaking changes from 4.x to 5.x, please refer to [the breaking changes document](https://github.com/ionic-team/ionic/blob/master/BREAKING.md#version-5x) in the Ionic core repo.
If you would like a fresh project starter, a new project base can be created from the CLI and an existing app can be migrated over manually.
39
-
40
-
## Migrating from Ionic 3.0 to Ionic 4.0
41
-
42
-
:::note
43
-
For a **complete list of breaking changes** from Ionic 3 to Ionic 4, please refer to [the breaking changes document](https://github.com/ionic-team/ionic/blob/master/angular/BREAKING.md) in the Ionic core repo.
44
-
:::
45
-
46
-
We suggest the following general process when migrating an existing application from Ionic 3 to 4:
47
-
48
-
1. Generate a new project using the `blank` starter (see [Starting an App](../developing/starting.md))
49
-
1. Copy any Angular services from `src/providers` to `src/app/services`
50
-
- Services should include `{ providedIn: 'root' }` in the `@Injectable()` decorator. For details, please see Angular [provider docs](https://angular.io/guide/providers).
51
-
1. Copy the app's other root-level items (pipes, components, etc) keeping in mind that the directory structure changes from `src/components` to `src/app/components`, etc.
52
-
1. Copy global Sass styling from `src/app/app.scss` to `src/global.scss`
53
-
1. Copy the rest of the application, page by page or feature by feature, keeping the following items in mind:
54
-
- Emulated Shadow DOM is turned on by default
55
-
- Page/component Sass should no longer be wrapped in the page/component tag and should use Angular's [`styleUrls`](https://angular.io/api/core/Component#styleUrls) option of the `@Component` decorator
56
-
- RxJS has been updated from v5 to v6 (see [RxJS Changes](#rxjs-changes))
57
-
- Certain lifecycle hooks should be replaced by Angular's hooks (see [Lifecycle Events](#lifecycle-events))
58
-
- Markup changes may be required (migration tool available, see [Markup Changes](#markup-changes))
59
-
60
-
In many cases, using the Ionic CLI to generate a new object and then copying the code also works very well. For example: `ionic g service weather` will create a shell `Weather` service and test. The code can then be copied from the older project with minor modifications as needed. This helps to ensure the proper structure is followed. This also generates shells for unit tests.
61
-
62
-
## Changes in Package Name
63
-
64
-
In Ionic 4, the package name is `@ionic/angular`. Uninstall Ionic 3 and install Ionic 4 using the new package name:
65
-
66
-
```shell
67
-
$ npm uninstall ionic-angular
68
-
$ npm install @ionic/angular
69
-
```
70
-
71
-
While migrating an app, update the imports from `ionic-angular` to `@ionic/angular`.
72
-
73
-
## Project structure
74
-
75
-
One of the major changes between an Ionic 3 app and an Ionic 4 app is the overall project layout and structure. In v3, Ionic apps had a custom convention for how an app should be set up and what that folder structure should look like. In v4, this has been changed to follow the recommended setup of each supported framework.
76
-
77
-
For example, if an app is using Angular, that project structure will be exactly what an Angular CLI app would be. This change, while not too difficult to accommodate, helps to keep common patterns and documentation consistent.
78
-
79
-
````mdx-code-block
80
-
<Tabs
81
-
defaultValue="v4"
82
-
values={[
83
-
{ value: 'v4', label: 'Ionic 4' },
84
-
{ value: 'v3', label: 'Ionic 3' },
85
-
]
86
-
}>
87
-
<TabItem value="v4">
88
-
89
-
```bash
90
-
src/
91
-
├── app/
92
-
│ ├── about/
93
-
│ ├── home/
94
-
│ ├── app-routing.module.ts
95
-
│ ├── app.component.html
96
-
│ ├── app.component.spec.ts
97
-
│ ├── app.component.ts
98
-
│ └── app.module.ts
99
-
├── assets/
100
-
├── environments/
101
-
├── theme/
102
-
├── global.scss
103
-
├── index.html
104
-
├── karma.conf.js
105
-
├── main.ts
106
-
├── polyfills.ts
107
-
├── test.ts
108
-
├── tsconfig.app.json
109
-
└── tsconfig.spec.json
110
-
.gitignore
111
-
angular.json
112
-
ionic.config.json
113
-
package.json
114
-
tsconfig.json
115
-
tslint.json
116
-
```
117
-
118
-
</TabItem>
119
-
<TabItem value="v3">
120
-
121
-
```bash
122
-
src/
123
-
├── app/
124
-
│ ├── app.component.html
125
-
│ ├── app.html
126
-
│ ├── app.module.ts
127
-
│ ├── app.scss
128
-
│ └── main.ts
129
-
├── assets/
130
-
├── pages/
131
-
│ ├── about/
132
-
│ ├── home/
133
-
├── theme/
134
-
├── index.html
135
-
├── manifest.json
136
-
└── service-worker.js
137
-
.gitignore
138
-
ionic.config.json
139
-
package.json
140
-
tsconfig.json
141
-
tslint.json
142
-
```
143
-
144
-
</TabItem>
145
-
</Tabs>
146
-
````
147
-
148
-
The above comparison is an example of a v4 app's project structure. For developers with experience in a vanilla Angular project, this should feel really familiar.
149
-
150
-
There is a `src/` directory that acts as the home for the app. This includes the `index.html`, any assets, environment configuration, and any app-specific config files.
151
-
152
-
While migrating an app to take advantage of this new layout, it is suggested that a new project "base" is made with the CLI. Then, with the new project layout, migrate the features of the app piece by piece. Pages/components/etc. should be moved into the `src/app/` folder.
153
-
154
-
Ensure your Ionic configuration file has the appropriate `type`. The project type for v3 is `ionic-angular`. The project type for v4 is `angular`. If this value is incorrect, the CLI may invoke the incorrect build scripts.
155
-
156
-
See the following `ionic.config.json` as an example:
157
-
158
-
```json
159
-
{
160
-
"name": "my-app",
161
-
"type": "angular"
162
-
}
163
-
```
164
-
165
-
## RxJS Changes
166
-
167
-
Between V3 and V4, RxJS was updated to version 6. This changes many of the import paths of operators and core RxJS functions. Please see the <ahref="https://github.com/ReactiveX/rxjs/blob/6.x/docs_app/content/guide/v6/migration.md"target="_blank">RxJS Migration Guide</a> for details.
168
-
169
-
## Lifecycle Events
170
-
171
-
With V4, we're now able to utilize the typical events provided by [Angular](https://angular.io/guide/lifecycle-hooks). But for certain cases, you might want to have access to the events fired when a component has finished animating during its route change. In this case, the `ionViewWillEnter`, `ionViewDidEnter`, `ionViewWillLeave`, and `ionViewDidLeave` have been ported over from V3. Use these events to coordinate actions with Ionic's own animations system.
172
-
173
-
Older events like `ionViewDidLoad`, `ionViewCanLeave`, and `ionViewCanEnter` have been removed, and the proper Angular alternatives should be used.
174
-
175
-
For more details, check out the [router-outlet docs](../api/router-outlet.md)
176
-
177
-
## Overlay Components
178
-
179
-
In prior versions of Ionic, overlay components such as Loading, Toast, or Alert were created synchronously. In Ionic v4, these components are all created asynchronously. As a result of this, the API is now promise-based.
180
-
181
-
```tsx
182
-
// v3
183
-
showAlert() {
184
-
const alert =this.alertCtrl.create({
185
-
message: "Hello There",
186
-
subHeader: "I'm a subheader"
187
-
});
188
-
189
-
alert.present();
190
-
}
191
-
```
192
-
193
-
In v4, promises are used:
194
-
195
-
```tsx
196
-
showAlert() {
197
-
this.alertCtrl.create({
198
-
message: "Hello There",
199
-
subHeader: "I'm a subheader"
200
-
}).then(alert=>alert.present());
201
-
}
202
-
203
-
// Or using async/await
204
-
205
-
asyncshowAlert() {
206
-
const alert =awaitthis.alertCtrl.create({
207
-
message: "Hello There",
208
-
subHeader: "I'm a subheader"
209
-
});
210
-
211
-
awaitalert.present();
212
-
}
213
-
```
214
-
215
-
## Navigation
216
-
217
-
In V4, navigation received the most changes. Now, instead of using Ionic's own `NavController`, we integrate with the official Angular Router. This not only provides a consistent routing experience across apps, but is much more dependable. The Angular team has an <ahref="http://angular.io/guide/router"target="_blank">excellent guide</a> on their docs site that covers the Router in great detail.
218
-
219
-
To provide the platform-specific animations that users are used to, we have created `ion-router-outlet` for Angular Apps. This behaves in a similar manner to Angular's `router-outlet` but provides a stack-based navigation (tabs) and animations.
220
-
221
-
For a detailed explanation in navigation works in a V4 project, check out the [Angular navigation guide](../angular/navigation.md).
222
-
223
-
## Lazy Loading
224
-
225
-
Since Navigation has changed, the mechanism for lazy loading has also changed in V4.
226
-
227
-
In v3, a typical lazy loading setup worked like this:
228
-
229
-
```tsx
230
-
// home.page.ts
231
-
@IonicPage({
232
-
segment: 'home'
233
-
})
234
-
@Component({ ... })
235
-
exportclassHomePage {}
236
-
237
-
// home.module.ts
238
-
@NgModule({
239
-
declarations: [HomePage],
240
-
imports: [IonicPageModule.forChild(HomePage)]
241
-
})
242
-
exportclassHomePageModule {}
243
-
```
244
-
245
-
However, in v4, lazy loading is done via the `loadChildren` method of the Angular router:
For a detailed explanation of lazy loading in V4 project, check out the [Angular navigation guide](../angular/navigation.md#lazy-loading-routes).
272
-
273
-
## Markup Changes
274
-
275
-
Since v4 moved to Custom Elements, there's been a significant change to the markup for each component. These changes have all been made to follow the Custom Elements spec, and have been documented in a <ahref="https://github.com/ionic-team/ionic/blob/master/angular/BREAKING.md#breaking-changes"target="_blank">dedicated file on GitHub</a>.
276
-
277
-
To help with these markup changes, we've released a TSLint-based <ahref="https://github.com/ionic-team/v4-migration-tslint"target="_blank">Migration Tool</a>, which detects issues and can even fix some of them automatically.
278
-
279
-
## Migrating from Ionic 1.0 to Ionic 4.0
280
-
281
-
### Ionic 1.0 to Ionic 4.0: What’s Involved?
282
-
283
-
Migrating from Ionic 1 to Ionic 4.0 involves moving from AngularJS (aka Angular 1) to Angular 7+. There are many architectural differences between these versions, so some of the app code will have to be rewritten. The amount of work involved depends on the complexity and size of your app.
284
-
285
-
One upside is that for the most part, the Ionic UI components you know and love from V1 haven’t changed much.
286
-
287
-
Here are some considerations to review before beginning the upgrade:
288
-
289
-
-**App complexity**: Naturally, the larger and more complex the app is, the longer it will take to migrate.
290
-
-**Framework support**: In 2019, Ionic will release full support for React. You can also use Ionic Framework components [without a framework](../intro/cdn.md). Since these are not production-ready yet, we recommend sticking with Angular or waiting until the other framework support is available.
291
-
-**Budget and team makeup**: The length of a migration project will vary based on the size of your team, the complexity of the app, and the amount of time allotted to make the transition.
292
-
293
-
### Suggested Strategy
294
-
295
-
Once your development team has identified a good time frame for beginning the migration, Ionic recommends feature-freezing the Ionic 1 application and getting the code in order: Fix any major bugs, eliminate tech debt, and reorganize as you see fit. Then, identify which features to migrate over and which to abandon.
296
-
297
-
Once the Ionic 1 app is stable, create a new Ionic 4.0 project. The majority of the dev team’s attention should be given to the new project; only bugs should be fixed in the Ionic 1 app to ensure that the transition happens as quickly and smoothly as possible.
298
-
299
-
Once the team is comfortable that the Ionic 4.0 app has become stable and has fulfilled a core set of features, you can then shut down the Ionic 1 app.
300
-
301
-
### Moving From AngularJS to Angular
302
-
303
-
Please reference official [Angular upgrade guide](https://angular.io/guide/upgrade) information.
304
-
305
-
### Ionic Changes
306
-
307
-
Our Ionic 3.0 to Ionic 4.0 migration sections above may prove to be a useful reference. Generate a new Ionic 4.0 project using the blank starter (see [Starting an App](../developing/starting.md)). Spend time getting familiar with Ionic 4.0 components. Happy building!
308
-
309
-
### Need Assistance?
310
-
311
-
If your team would like assistance with the migration, please [reach out to us](https://ionicframework.com/enterprise-engine)! Ionic offers Advisory Services, which includes Ionic 4.0 training, architecture reviews, and migration assistance.
16
+
Please see the [Ionic 4 Migration Guide](/docs/updating/4-0).
0 commit comments