'router-outlet' is not a known element

后端 未结 12 1145
无人及你
无人及你 2021-01-30 19:36

I have a mvc 5 project with a angular frontend . I wanted to add routing as described in this tutorial https://angular.io/guide/router. So in my _Layout.cshtml I ad

12条回答
  •  春和景丽
    2021-01-30 19:59

    Its just better to create a routing component that would handle all your routes! From the angular website documentation! That's good practice!

    ng generate module app-routing --flat --module=app

    The above CLI generates a routing module and adds to your app module, all you need to do from the generated component is to declare your routes, also don't forget to add this:

    exports: [
        RouterModule
      ],
    

    to your ng-module decorator as it doesn't come with the generated app-routing module by default!

提交回复
热议问题