9
9
In this step, you will learn how to create a layout template and how to build an application that
10
10
has multiple views by adding routing, using an Angular module called {@link ngRoute ngRoute}.
11
11
12
- * When you now navigate to `/index.html`, you are redirected to `/index.html#/phones` and the phone
12
+ * When you now navigate to `/index.html`, you are redirected to `/index.html#! /phones` and the phone
13
13
list appears in the browser.
14
14
* When you click on a phone link, the URL changes to that specific phone and the stub of a phone
15
15
detail page is displayed.
@@ -193,18 +193,20 @@ angular.module('phonecatApp', [
193
193
]);
194
194
```
195
195
196
- Now we can configure the `$route` service (using it's provider) for our application. In order to be
197
- able to quickly locate the configuration code, we put it into a separate file and used the `.config`
198
- suffix.
196
+ Now, in addition to the core services and directives, we can also configure the `$route` service
197
+ (using it's provider) for our application. In order to be able to quickly locate the configuration
198
+ code, we put it into a separate file and used the `.config` suffix.
199
199
200
200
<br />
201
201
**`app/app.config.js`:**
202
202
203
203
```js
204
204
angular.
205
205
module('phonecatApp').
206
- config(['$routeProvider',
207
- function config($routeProvider) {
206
+ config(['$locationProvider', '$routeProvider',
207
+ function config($locationProvider, $routeProvider) {
208
+ $locationProvider.hashPrefix('!');
209
+
208
210
$routeProvider.
209
211
when('/phones', {
210
212
template: '<phone-list></phone-list>'
@@ -217,11 +219,25 @@ suffix.
217
219
]);
218
220
```
219
221
220
- Using the `.config()` method, we request the `$routeProvider` to be injected into our configuration
221
- function and use the {@link ngRoute.$routeProvider#when $routeProvider.when()} and
222
+ Using the `.config()` method, we request the necessary providers (for example the `$routeProvider`)
223
+ to be injected into our configuration function and then use their methods to specify the behavior of
224
+ the corresponding services. Here, we use the
225
+ {@link ngRoute.$routeProvider#when $routeProvider.when()} and
222
226
{@link ngRoute.$routeProvider#otherwise $routeProvider.otherwise()} methods to define our
223
227
application routes.
224
228
229
+ <div class="alert alert-success">
230
+ <p>
231
+ We also used {@ink $locationProvider#hashPrefix $locationProvider.hashPrefix()} to set the
232
+ hash-prefix to `!`. This prefix will appear in the links to our client-side routes, right after
233
+ the hash (`#`) symbol and before the actual path (e.g. `index.html#!/some/path`).
234
+ </p>
235
+ <p>
236
+ Setting a prefix is not necessary, but it is considered a good practice (for reasons that are
237
+ outside the scope of this tutorial). `!` is the most commonly used prefix.
238
+ </p>
239
+ </div>
240
+
225
241
Our routes are defined as follows:
226
242
227
243
* `when('/phones')`: Determines the view that will be shown, when the URL hash fragment is
@@ -345,7 +361,7 @@ various URLs and verifying that the correct view was rendered.
345
361
```js
346
362
...
347
363
348
- it('should redirect `index.html` to `index.html#/phones', function() {
364
+ it('should redirect `index.html` to `index.html#! /phones', function() {
349
365
browser.get('index.html');
350
366
expect(browser.getLocationAbsUrl()).toBe('/phones');
351
367
});
@@ -355,7 +371,7 @@ various URLs and verifying that the correct view was rendered.
355
371
describe('View: Phone list', function() {
356
372
357
373
beforeEach(function() {
358
- browser.get('index.html#/phones');
374
+ browser.get('index.html#! /phones');
359
375
});
360
376
361
377
...
@@ -367,7 +383,7 @@ various URLs and verifying that the correct view was rendered.
367
383
describe('View: Phone details', function() {
368
384
369
385
beforeEach(function() {
370
- browser.get('index.html#/phones/nexus-s');
386
+ browser.get('index.html#! /phones/nexus-s');
371
387
});
372
388
373
389
it('should display placeholder page with `phoneId`', function() {
0 commit comments