Skip to content

Commit e15a66b

Browse files
committed
Part 2: Add UI Router With Config
1 parent 36374b4 commit e15a66b

File tree

10 files changed

+1044
-1004
lines changed

10 files changed

+1044
-1004
lines changed

guide/overview.md

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,11 @@ npx @angular/cli new your-project-name
1414

1515
See [Part 1](./part-1.md)
1616

17-
## 2. Add Angular Router With Config
17+
## 2. Add UI Router With Config
1818

19-
// ....
20-
21-
## 3. Add UI Router With Config
22-
23-
```sh
24-
npm install --save angular-ui-router
25-
```
26-
27-
```ts
28-
import 'angular-ui-router';
29-
30-
export const legacyApp = angular.module('legacyApp', ['ui.router']);
31-
```
19+
See [Part 2](./part-2.md)
3220

21+
## 3. Add Angular Router With Config
3322

3423
// ...
3524

guide/part-2.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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

Comments
 (0)