Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

Commit fdbb7b5

Browse files
committed
docs(router): clarify router redirect and link to Victor's blog post
1 parent f3da5c8 commit fdbb7b5

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

public/docs/ts/latest/guide/router.jade

+17-6
Original file line numberDiff line numberDiff line change
@@ -978,22 +978,33 @@ code-example(format="").
978978
We prefer that the application display the list of crises as it would if the user clicked the "Crisis Center" link or pasted `localhost:3000/crisis-center/` into the address bar.
979979
This is our intended default route.
980980

981-
The preferred solution is to add a `redirect` route that transparently translates from the initial URL (`''`) to the preferred default path (`/crisis-center`):
981+
The preferred solution is to add a `redirect` route that transparently translates from the initial relative URL (`''`)
982+
to the desired default path (`/crisis-center`):
982983
+makeExample('router/ts/app/crisis-center/crisis-center.routes.2.ts', 'redirect', 'app/crisis-center/crisis-center.routes.ts (redirect route)' )(format='.')
983984

984985
:marked
985986
A redirect route requires a `pathMatch` property to tell the router how to match a URL to the path of a route.
986-
In this app, the router should select the route to `CrisisCenterComponent` when the *entire URL* matches `''`,
987+
In this app, the router should select the route to the `CrisisListComponent` when the *entire URL* matches `''`,
987988
so we set the `pathMatch` value to `'full'`.
988989

989990
.l-sub-section
990991
:marked
992+
Technically, `pathMatch = 'full'` results in a route hit when the *remaining*, unmatched segments of the URL match `''`.
993+
In our example, the redirect is at the top level of the route configuration tree so the *remaining* URL and the *entire* URL
994+
are the same thing.
995+
991996
The other possible `pathMatch` value is `'prefix'` which tells the router
992-
to match the redirect route to _any_ URL that _begins_ with the redirect route's _prefix_ path.
997+
to match the redirect route when the *remaining* URL ***begins*** with the redirect route's _prefix_ path.
998+
999+
That's not what we want to do here. If the `pathMatch` value were `'prefix'`,
1000+
_every_ URL would match `''`.
1001+
We could never navigate to `/crisis-center/1` because the redirect route would match first and
1002+
send us to the `CrisisListComponent`.
9931003

994-
That's not what we want in our use case. The `''` prefix path matches _every_ URL.
995-
We should redirect to the `CrisisCenterComponent` _only_ when the _entire_ url is `''`
996-
(or the equivalent `'/'`).
1004+
We should redirect to the `CrisisListComponent` _only_ when the _entire (remaining)_ url is `''`.
1005+
1006+
Learn more in Victor Savkin's blog
1007+
[post on redirects](http://victorsavkin.com/post/146722301646/angular-router-empty-paths-componentless-routes).
9971008

9981009
We'll discuss redirects in more detail in a future update to this chapter.
9991010

0 commit comments

Comments
 (0)