fix: sync to 6.0(WIP)
This commit is contained in:
parent
11e0635d0d
commit
5391220474
@ -2304,8 +2304,7 @@ They are distributed across two modules, `AppRoutingModule` and `HeroesRoutingMo
|
|||||||
Each routing module augments the route configuration _in the order of import_.
|
Each routing module augments the route configuration _in the order of import_.
|
||||||
If you list `AppRoutingModule` first, the wildcard route will be registered
|
If you list `AppRoutingModule` first, the wildcard route will be registered
|
||||||
_before_ the hero routes.
|
_before_ the hero routes.
|
||||||
The wildcard route — which matches _every_ URL —
|
The wildcard route—which matches _every_ URL—will intercept the attempt to navigate to a hero route.
|
||||||
will intercept the attempt to navigate to a hero route.
|
|
||||||
|
|
||||||
每个路由模块都会根据*导入的顺序*把自己的路由配置追加进去。
|
每个路由模块都会根据*导入的顺序*把自己的路由配置追加进去。
|
||||||
如果你先列出了 `AppRoutingModule`,那么通配符路由就会被注册在“英雄管理”路由*之前*。
|
如果你先列出了 `AppRoutingModule`,那么通配符路由就会被注册在“英雄管理”路由*之前*。
|
||||||
@ -4321,7 +4320,7 @@ Here's a demo `AuthService`:
|
|||||||
Although it doesn't actually log in, it has what you need for this discussion.
|
Although it doesn't actually log in, it has what you need for this discussion.
|
||||||
It has an `isLoggedIn` flag to tell you whether the user is authenticated.
|
It has an `isLoggedIn` flag to tell you whether the user is authenticated.
|
||||||
Its `login` method simulates an API call to an external service by returning an
|
Its `login` method simulates an API call to an external service by returning an
|
||||||
Observable that resolves successfully after a short pause.
|
observable that resolves successfully after a short pause.
|
||||||
The `redirectUrl` property will store the attempted URL so you can navigate to it after authenticating.
|
The `redirectUrl` property will store the attempted URL so you can navigate to it after authenticating.
|
||||||
|
|
||||||
虽然它不会真的进行登录,但足够让你进行这个讨论了。
|
虽然它不会真的进行登录,但足够让你进行这个讨论了。
|
||||||
@ -4725,17 +4724,14 @@ That method could return a `Promise`, an `Observable`, or a synchronous return v
|
|||||||
注入 `CrisisService` 和 `Router`,并实现 `resolve()` 方法。
|
注入 `CrisisService` 和 `Router`,并实现 `resolve()` 方法。
|
||||||
该方法可以返回一个 `Promise`、一个 `Observable` 来支持异步方式,或者直接返回一个值来支持同步方式。
|
该方法可以返回一个 `Promise`、一个 `Observable` 来支持异步方式,或者直接返回一个值来支持同步方式。
|
||||||
|
|
||||||
The `CrisisService.getCrisis` method returns an Observable.
|
The `CrisisService.getCrisis` method returns an observable, in order to prevent the route from loading until the data is fetched.
|
||||||
Return that observable to prevent the route from loading until the data is fetched.
|
The `Router` guards require an observable to `complete`, meaning it has emitted all
|
||||||
The `Router` guards require an Observable to `complete`, meaning it has emitted all
|
|
||||||
of its values. You use the `take` operator with an argument of `1` to ensure that the
|
of its values. You use the `take` operator with an argument of `1` to ensure that the
|
||||||
Observable completes after retrieving the first value from the Observable returned by the
|
observable completes after retrieving the first value from the observable returned by the
|
||||||
`getCrisis` method.
|
`getCrisis` method. If it doesn't return a valid `Crisis`, navigate the user back to the `CrisisListComponent`,
|
||||||
If it doesn't return a valid `Crisis`, navigate the user back to the `CrisisListComponent`,
|
|
||||||
canceling the previous in-flight navigation to the `CrisisDetailComponent`.
|
canceling the previous in-flight navigation to the `CrisisDetailComponent`.
|
||||||
|
|
||||||
`CrisisService.getCrisis` 方法返回了一个 `Promise`。
|
`CrisisService.getCrisis` 方法返回了一个可观察对象,这是为了防止在数据获取完毕前加载路由。
|
||||||
返回 `Promise` 可以阻止路由被加载,直到数据获取完毕。
|
|
||||||
如果它没有返回一个有效的 `Crisis`,就把用户导航回 `CrisisListComponent`,并取消以前到 `CrisisDetailComponent` 尚未完成的导航。
|
如果它没有返回一个有效的 `Crisis`,就把用户导航回 `CrisisListComponent`,并取消以前到 `CrisisDetailComponent` 尚未完成的导航。
|
||||||
|
|
||||||
Import this resolver in the `crisis-center-routing.module.ts`
|
Import this resolver in the `crisis-center-routing.module.ts`
|
||||||
@ -4780,8 +4776,8 @@ That's the router's job. Write this class and let the router take it from there.
|
|||||||
|
|
||||||
要依赖路由器调用此守卫。不必关心用户用哪种方式导航离开,这是路由器的工作。你只要写出这个类,等路由器从那里取出它就可以了。
|
要依赖路由器调用此守卫。不必关心用户用哪种方式导航离开,这是路由器的工作。你只要写出这个类,等路由器从那里取出它就可以了。
|
||||||
|
|
||||||
1. The Observable provided to the Router _must_ complete.
|
1. The observable provided to the Router _must_ complete.
|
||||||
If the Observable does not complete, the navigation will not continue.
|
If the observable does not complete, the navigation will not continue.
|
||||||
|
|
||||||
由路由器提供的 Observable *必须* 完成(complete),否则导航不会继续。
|
由路由器提供的 Observable *必须* 完成(complete),否则导航不会继续。
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user