To solve this problem change this line:
imports: [RouterModule.forChild(routes)],
to:
imports: [RouterModule.forRoot(routes)],
The error is caused because RouterModule.forChild() generates a module that contains the necessary directives and routes but doesn’t include the routing service. That is what RouterModule.forRoot is for: it generates a module that contains the necessary directives, routes, and the routing service.
More information in Angular docs: Angular – Router Module.