Pass the result of one solution to another using Angular Router

I know how to create multiple permission classes for a route, but I don't know how to pass the result of one solution to another solution.

// Example Route { path: 'book/:id', component: BookComponent, resolve: { document: BookResolve, title: BookTitleResolve } } 

If BookResolve returns a book object, how can you pass this book object to BookTitleResolve ?

I have a title service that is looking for title data. I need to create a book title from a book object. It must be dynamic.

+7
angular routing
source share
1 answer

It is allowed within the same component launch at the same time, but it allows parents to finish before the children, so the easiest way to achieve this is to create a parent route in order to resolve the book.

 { path: 'book/:id', resolve: { document: BookResolve }, children: [ { path: '', component: BookComponent, resolve: { title: BookTitleResolve } } ] } 

Please note that the parent component does not display the component, and the child element contains an empty path, therefore, despite some added pattern, the route should act equally functionally.

Then, inside your implementation of BookTitleResolve, you can get the original route:

 class BookTitleResolve { resolve(route: ActivatedRouteSnapshot) { // Do something with route.parent.data.document } } 
+2
source share

All Articles