|
| 1 | +# 2. Add UI Router With Config |
| 2 | + |
| 3 | +## Install Angular UI Router |
| 4 | + |
| 5 | +```sh |
| 6 | +npm install --save angular-ui-router |
| 7 | +``` |
| 8 | + |
| 9 | +## Configure LegacyApp Module |
| 10 | + |
| 11 | +[legacy.app.module.ts](../src/app/legacy/legacy.app.module.ts) |
| 12 | + |
| 13 | +```ts |
| 14 | +import angularUiRouter from 'angular-ui-router'; |
| 15 | + |
| 16 | +export const legacyApp = angular.module('legacyApp', [ |
| 17 | + angularUiRouter, |
| 18 | +]) |
| 19 | +.config(['$locationProvider', ($locationProvider) => { |
| 20 | + $locationProvider.html5Mode({ enabled: true, requireBase: false }); |
| 21 | +}]); |
| 22 | +``` |
| 23 | + |
| 24 | +## Configure Routes |
| 25 | + |
| 26 | +Create a `legacy/routing` folder for our routes file: |
| 27 | + |
| 28 | +[legacy.routes.ts](../src/app/legacy/routing/legacy.routes.ts) |
| 29 | + |
| 30 | +```ts |
| 31 | +legacyApp.config(legacyRoutes); |
| 32 | + |
| 33 | +legacyRoutes.$inject = ['$stateProvider']; |
| 34 | +function legacyRoutes($stateProvider) { |
| 35 | + $stateProvider |
| 36 | + .state('HelloAjs', { |
| 37 | + url: '/hello-ajs', |
| 38 | + template: ` |
| 39 | + <div class="comp ajs"> |
| 40 | + <h3>Hello from AngularJs Route</h3> |
| 41 | + </div> |
| 42 | + `, |
| 43 | + }); |
| 44 | +} |
| 45 | +``` |
| 46 | + |
| 47 | +You'll also want an `index.ts` file in that folder to assist importing. |
| 48 | + |
| 49 | +[legacy/routing/index.ts](../src/app/legacy/routing/index.ts) |
| 50 | + |
| 51 | +```ts |
| 52 | +import './legacy.routes'; |
| 53 | +``` |
| 54 | + |
| 55 | +And update the `legacy/index` file. |
| 56 | + |
| 57 | +[legacy/index.ts](../src/app/legacy/index.ts) |
| 58 | + |
| 59 | +```ts |
| 60 | +import './routing'; |
| 61 | +``` |
| 62 | + |
| 63 | +## Update LegacyApp Component Template |
| 64 | + |
| 65 | +[legacy.app.component.ts](../src/app/legacy/legacy.app.component.ts) |
| 66 | + |
| 67 | +```ts |
| 68 | +legacyApp.component(LEGACY_APP_COMP_SELECTOR, { |
| 69 | + template: ` |
| 70 | + <div class="comp ajs"> |
| 71 | + <h2>Legacy App Component</h2> |
| 72 | + <ui-view></ui-view> |
| 73 | + <div> |
| 74 | + ` |
| 75 | +}); |
| 76 | +``` |
| 77 | + |
| 78 | +## Navigate to route |
| 79 | + |
| 80 | +Navigate to [/hello-ajs](http://localhost:4200/hello-ajs). |
| 81 | + |
| 82 | +Now you should have a your angularJs routing set up! |
| 83 | + |
| 84 | +## Next step |
| 85 | + |
| 86 | +[Part 3: Add Angular Router With Config](./part-3.md) |
0 commit comments