Base solution for your next web application
Open Closed

ASP Zero - Angular 7 Routing #7170


User avatar
0
miroslav.engi created

I've created two Components one for list, other for details.

Created two routes in main.routing.module.ts

    { path: 'finishedGoods/truck-packing', component: DeliveryPlanningListComponent },
    { path: 'finishedGoods/truck-packing-details/:id', component: PackingDetailsComponent },

Then in PackagingDetailsComponent html i created a button with route

 <button routerLink = "/finishedGoods/truck-packing-details/{{record.deliveryNote.id}}">test</button>

I get an error : Error: Cannot match any routes. URL Segment: 'finishedGoods/truck-packing-details/2'

When I write the link in browser it works, so the route is working but its not generated correctly with routerLink directive in html component.

Also when I add app/main to link

<button routerLink = "/app/main/finishedGoods/truckPackingDetails/{{record.deliveryNote.id}}">test</button>

Then it is working, how should I resolve this ?


3 Answer(s)
  • User Avatar
    0
    leonkosak created

    I do not understand what is your problem exactly. Just prefix "/app/main" and that's it. Before "/app" is "base URL". It's also good to have ability to change module (we do not implement application inside "main" but inside our custom Angular modules".

  • User Avatar
    0
    miroslav.engi created

    It should work with:

    [routerLink]="['/finishedGoods/truck-packing-details', record.deliveryNote.id]"
    

    But it throws error: Error: Cannot match any routes. URL Segment: 'finishedGoods/truckPackingDetails/2'

    Why do I need to add "app/main" in front of it ?

  • User Avatar
    0
    ryancyq created
    Support Team

    Hi,

    The app/main/ is needed as the routes are added to main.routing.module.ts which is a child route of app.routing.module.ts and root.routing.module.ts.