Open Closed

Route parameters #9422


0
MASITEK_ASPNETZERO created

Hi, I would like to add parameters to the menu links in the main menu. Currently I have a parent called "Requisitions" and under that I have 3 options and want them all to use the same view but want to pass in a parameter to tell the view the type of requisition. How can I do that?

Here is the NavigationProvider code:

).AddItem(new MenuItemDefinition(
                    PageNames.App.Tenant.Requisitions,
                    L("Requisitions"),
                     icon: "fa fa-files-o"
                    ).AddItem(new MenuItemDefinition(
                        PageNames.App.Tenant.RequisitionsMaterial,
                        L("NewMaterialRequisition"),
                        url: "tenant.requisitionsmaterial",
                        icon: "fa fa-circle",
                        permissionDependency: new SimplePermissionDependency(AppPermissions.Pages_Tenant_Requisitions_Material_Add),
                        customData: new System.Collections.Generic.Dictionary<string, string>() { { "type", "material" } }
                        )
                    ).AddItem(new MenuItemDefinition(
                        PageNames.App.Tenant.RequisitionsStock,
                        L("NewStockRequisition"),
                        url: "tenant.requisitionsstock",
                        icon: "fa fa-circle",
                        permissionDependency: new SimplePermissionDependency(AppPermissions.Pages_Tenant_Requisitions_Stock_Add),
                        customData: new System.Collections.Generic.Dictionary<string, string>() { { "type", "stock" } }
                        )
                    ).AddItem(new MenuItemDefinition(
                        PageNames.App.Tenant.RequisitionsService,
                        L("NewServiceRequisition"),
                        url: "tenant.requisitionsservice",
                        icon: "fa fa-circle",
                        permissionDependency: new SimplePermissionDependency(AppPermissions.Pages_Tenant_Requisitions_Service_Add),
                        customData: new System.Collections.Generic.Dictionary<string, string>() { { "type", "service" } }
                        )
                    )

Here is the app.js routes:

 if (abp.auth.hasPermission('Pages.Tenant.Requisitions')) {
            $stateProvider.state('tenant.requisitions', {
                url: '/requisitions',
                templateUrl: '~/App/tenant/views/requisitions/index.cshtml'
            });

            $stateProvider.state('tenant.requisitionsmaterial', {
                url: '/requisitions/requisition',
                templateUrl: '~/App/tenant/views/requisitions/requisition/index.cshtml'
            });
      
            $stateProvider.state('tenant.requisitionsservice', {
                url: '/requisitions/requisition/',
                templateUrl: '~/App/tenant/views/requisitions/requisition/index.cshtml'
            });
              
            $stateProvider.state('tenant.requisitionsstock', {
                url: '/requisitions/requisition',
                templateUrl: '~/App/tenant/views/requisitions/requisition/index.cshtml'
            });
        }

I have tried these for example on the 'tenant.requisitionsstock' route:

url: '/requisitions/requisition/:stock'   (where stock is a string var)
url: '/requisitions/requisition?type=stock'
url: '/requisitions/requisition/{stock}'  (where stock is a var {type:'stock'}

When i print out the $stateParams on js side of the view, it's always {stock:""} or {"type:""} or {stock: undefined} Can someone please point me in the right direction. I want to avoid using three different views for each because there are only minor differenes between the three views. Thanks.


3 Answer(s)
  • 1
    ismcagdas created
    Support Team

    Hi,

    Defining the route as we do here and then passing the parameter via query string should work. Did you try that ?

  • 0
    MASITEK_ASPNETZERO created

    Hi,

    I am trying to pass it in like the language example but the difference is I am clicking an item in the nav menu. How can I change the code below to pass in the parameter?

     ).AddItem(new MenuItemDefinition(
            PageNames.App.Tenant.RequisitionsService,
            L("NewServiceRequisition"),
            url: "tenant.requisitionsservice",
            icon: "fa fa-circle",
            permissionDependency: new SimplePermissionDependency(AppPermissions.Pages_Tenant_Requisitions_Service_Add)
    
            )
    

    The language example passes the parameter in the $state.go function.

  • 0
    MASITEK_ASPNETZERO created

    I wasn't understanding how to use the routes property, your link helped and was exactly what I needed, thanks!