Open Closed

How do I add an ABP.Route configuration for Routes with placeholders? #9815


User avatar
0
mharnos created

Hi,

when I add an angular route for the path /examples/:exampleId how would I add the corresponding ABP.Route for this route entry? If I specify the same path (or undefined) and then navigate to that route, the Breadcrumbs + Icons are not correct (they return the fallback value for our main route at /)

Our route configuration currently looks like this:

export const EXAMPLE_ROUTE_NAMES = {
  a: 'subroute-a',
  b: 'subroute-b',
}

export const createExampleRoutes = (path: string, order?: number, group?: string): AbpRoute[] => {
  return [
    {
      path,
      canActivate: [ authGuard ],
      data: {
        routes: [
          {
            path: undefined,
            name: '::Menu:Examples',
            iconClass: 'fas fa-dolly-flatbed',
            layout: eLayoutType.application,
            order,
            group,
          },
          {
            path: `/${path}`,
            name: '::Menu:Examples:Overview',
            parentName: '::Menu:Examples',
            order: 1,
          },
          {
            path: `/${path}/:exampleId/${EXAMPLE_ROUTE_NAMES.a}`, // <<<<<< the issue is here ! >>>>>>>>
            name: '::Menu:Examples:A',
            parentName: '::Menu:Examples',
            order: 2,
          },
          {
            path: `/${path}/:exampleId/${EXAMPLE_ROUTE_NAMES.b}`, // <<<<<< the issue is here ! >>>>>>>>
            name: '::Menu:Examples:B',
            parentName: '::Menu:Examples',
            order: 3,
          },
        ],
      },
      children: [
        {
          path: '',
          component: ExampleComponent,
          title: '::Menu:Examples:Overview',
        },
        {
          path: ':exampleId', // <<<<< all components are injected with this `exampleId` >>>>>>>
          children: [
            {
              path: `${EXAMPLE_ROUTE_NAMES.a}`,
              component: ExampleComponent,
              title: '::Menu:Examples:A',
            },

            {
              path: `${EXAMPLE_ROUTE_NAMES.b}`,
              component: ExampleComponent,
              title: '::Menu:Examples:B',
            },
            // ... more routes ...
          ],
        },
      ],
    },
  ]
}

Do you have any idea how to provide the "Menu Configuration" / ABP.Route Data for those routes with path placeholders?

Kind Regards, Marc


5 Answer(s)
  • User Avatar
    0
    AI-Bot created
    Support Team ABP Agent

    To provide correct ABP.Route configuration for Angular routes with placeholders (such as :exampleId), you should define the path in your ABP.Route entries using the same placeholder syntax as in your Angular route definitions. This ensures that the menu, breadcrumbs, and icons are correctly resolved for dynamic routes.

    Here's how you can adjust your configuration:

    1. Use Placeholder Syntax in ABP.Route Paths
      The path property in your ABP.Route should match the Angular route, including placeholders. For example:
    {
         path: `/${path}/:exampleId/${EXAMPLE_ROUTE_NAMES.a}`,
         name: '::Menu:Examples:A',
         parentName: '::Menu:Examples',
         order: 2,
       },
       {
         path: `/${path}/:exampleId/${EXAMPLE_ROUTE_NAMES.b}`,
         name: '::Menu:Examples:B',
         parentName: '::Menu:Examples',
         order: 3,
       },
    

    This is correct and supported by the ABP Angular menu system.

    1. Ensure Consistency
      Make sure the path in your ABP.Route matches exactly the route definition in your Angular router, including the placeholder (e.g., :exampleId). This allows the ABP menu and breadcrumb system to resolve the correct menu item even for dynamic routes.

    2. Parent-Child Relationships
      Use the parentName property to establish the hierarchy for breadcrumbs and menu nesting.

    3. No Need for undefined Path
      Avoid using path: undefined for dynamic routes. Always specify the full path with placeholders.

    4. Example
      Here’s a minimal example for a dynamic route:

    {
         path: '/examples/:exampleId/subroute-a',
         name: '::Menu:Examples:A',
         parentName: '::Menu:Examples',
         order: 2,
       }
    
    1. Menu and Breadcrumbs
      With this setup, when you navigate to /examples/123/subroute-a, the ABP menu and breadcrumb system will correctly highlight and display the menu item for "A" under "Examples".

    Summary:
    Define your ABP.Route path with the same placeholder syntax as your Angular route (e.g., :exampleId). This enables the ABP Angular UI to resolve menu and breadcrumb items for dynamic routes.

    Sources:


    This response was generated by AI. If it didn’t solve your problem, feel free to post a new answer — our support team will jump in to help you soon.

  • User Avatar
    0
    mharnos created

    Hi, the ABP.Routes are already configured with the placeholder inside the path variable (like the AI suggested): /${path}/:exampleId/${EXAMPLE_ROUTE_NAMES.b}

  • User Avatar
    0
    sumeyye.kurtulus created
    Support Team Angular Expert

    Hello,

    You will need to eliminate manual route configuration by automatically generating both application routes and sidebar navigation based on your data.

    The structure actually works like this

    1. Application Routes (app.routes.ts)
      • Handles actual page navigation
      • Loads components when URLs are accessed
      • Defines the routing structure
    2. Sidebar Navigation (route.provider.ts)
      • Manages ABP sidebar menu items
      • Dynamically adds/removes navigation links
      • Keeps menu in sync with available routes

    I am sending a sample project for you to provide a better guidance: https://drive.google.com/file/d/1dSL9Aqm17E35LKPn-KxVDS0RZpF_n6IR/view?usp=drive_link

    Here in this project:

    • RouteManagerService handles sidebar updates
    • ExampleService manages data and route generation
    • RouteDemoComponent provides visual testing interface

    You can let us know if you need further assistance. Thank you for your cooperation.

  • User Avatar
    0
    mharnos created

    Hello Mrs. Kurtuluş,

    I was able to download the example project successfully and will look into it soon. Thank you for the example and explanation; I was somewhat aware that the data on the angular-routes was used for ABP.Routes (+Navbar generation +Breadcrum generation) but I'll look into your example in detail.

    We have some other problems related to Navbar (in particular the groups are not selected correctly, so sometimes the Admin-Group gets selected, even though I'm in my application route) -> maybe if we change our code to align with your example this will be resolved too, otherwise I'll open another ticket for it 👍

    I'll give feedback about this example shortly, but I'm not sure when exactly I'll be able to. (Maybe beginning of next week)

    Thanks, Marc

  • User Avatar
    0
    sumeyye.kurtulus created
    Support Team Angular Expert

    Hello Marc,

    I am glad to hear you were able to download the example project without any issues. Please feel free to take the time you need to review it — I will be happy to receive your feedback whenever it is convenient for you.

    Regarding the Navbar problem, it could indeed be resolved by aligning the implementation with the example. If not, please open another ticket, and we will look into it further.

    Thank you for the update, and I look forward to your thoughts once you have had a chance to explore the project.

Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.0.0-preview. Updated on September 01, 2025, 08:37