Configuration

You can now define operations on your routes. In the following example code, you see a simple getMany population for the PostsIndexComponent. We also define one child route for the selected Post entity.

Use the operate() function to define operators for your routes.

posts-routing.module.ts
import { getActive, getMany, reset } from '@ng-frrri/router-middleware/operators';

const all = 'entities';
const posts = 'entities.posts';

const routes: Routes = [
    {
        path: '',
        pathMatch: 'full',
        redirectTo: 'all',
    },
    {
        path: 'all',
        component: PostsIndexComponent,
        data: operate(
            reset(all),
            getMany(posts),
        ),
        children: [{
            path: ':id',
            component: PostsShowComponent,
            data: operate(
                getActive(posts),
            ),
        }],
    },
];

@NgModule({
    imports: [
        RouterModule.forChild(
            frrri(routes),
        ),
    ],
    exports: [RouterModule],
})
export class PostsRoutingModule { }

Find the list of already defined operators in our @ng-frrri/router-middleware repository. Please see the integration example in the GitHub repository to see the usage of a variety of predefined operators.

Last updated