Conversation
`GuideViewer` and `ComponentViewer` looked up their item from the route params themselves, and called `router.navigate` when nothing matched. That meant the component was created and rendered before the redirect, and the redirect started a second navigation. This moves the lookup into route resolvers. When an item is missing, the resolver returns a `RedirectCommand`, so the router redirects as part of the same navigation, before the component is created. When it's found, the item reaches the component as an input through `withComponentInputBinding()`. Changes: - Add `guideResolver` on the `guide/:id` route. It resolves the guide or redirects to `/guides`. - Add `docItemResolver` on the `:section/:id` route. It resolves the doc item or redirects to the section. - `GuideViewer`: replace the `id` input and lookup with a required `guide` input, and drop the `Router` and `GuideItems` injections. - `ComponentViewer`: replace the `id` and `section` inputs and the async lookup with a required `docItem` input. `componentDocItem` is now `toObservable(docItem)`, which replays the latest item like the old `ReplaySubject`, so the child pages are unchanged. The tabs in `sections` become a `computed`, so they're always in the same order instead of depending on the order of previous add/delete calls. Tests: - Run the `GuideViewer` and `ComponentViewer` specs against routes that use the resolvers, so they cover both the resolved inputs and the redirects. - Add a test for the tabs shown for a doc item.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
GuideViewerandComponentViewerlooked up their item from the route params themselves, and calledrouter.navigatewhen nothing matched. That meant the component was created and rendered before the redirect, and the redirect started a second navigation.This moves the lookup into route resolvers. When an item is missing, the resolver returns a
RedirectCommand, so the router redirects as part of the same navigation, before the component is created. When it's found, the item reaches the component as an input throughwithComponentInputBinding().Changes:
guideResolveron theguide/:idroute. It resolves the guide or redirects to/guides.docItemResolveron the:section/:idroute. It resolves the doc item or redirects to the section.GuideViewer: replace theidinput and lookup with a requiredguideinput, and drop theRouterandGuideItemsinjections.ComponentViewer: replace theidandsectioninputs and the async lookup with a requireddocIteminput.componentDocItemis nowtoObservable(docItem), which replays the latest item like the oldReplaySubject, so the child pages are unchanged. The tabs insectionsbecome acomputed, so they're always in the same order instead of depending on the order of previous add/delete calls.Tests:
GuideViewerandComponentViewerspecs against routes that use the resolvers, so they cover both the resolved inputs and the redirects.