AngualrJS routeProvider routing to the wrong template

I have the following 2 routes in my file app.js, for some reason I don’t know when I try to go to /clients/new-invoiceI see the route and the pattern /clients/:clientID. The only way I can go to the correct page is to delete the route /clients/:clientID.

I also noticed that this only started after I added :clientIDto the next route.

Can someone please help me by telling me what exactly am I doing wrong here?

    $routeProvider.when('/clients/:clientID', 
            {     templateUrl: 'templates/client-profile-view.html', 
                  controller: 'ClientsController',
                  title: 'Client Profile',
                  data: {
                     auth: true,
                     plevel: [5] 
                  }                
            });    


    $routeProvider.when('/clients/new-invoice', 
            {     templateUrl: 'templates/new-invoice.html', 
                  controller: 'InvoicesController',
                  title: 'New Invoice',
                  data: {
                     auth: true,
                     plevel: [5] 
                  }                
            });
+4
source share
4 answers

, /clients/:clientID /clients/new-invoice. . .

+7

, , :

$routeProvider.when('/clients/new-invoice', 
        {     templateUrl: 'templates/new-invoice.html', 
              controller: 'InvoicesController',
              title: 'New Invoice',
              data: {
                 auth: true,
                 plevel: [5] 
              }                
        })

.when('/clients/:clientID', 
        {     templateUrl: 'templates/client-profile-view.html', 
              controller: 'ClientsController',
              title: 'Client Profile',
              data: {
                 auth: true,
                 plevel: [5] 
              }                
        });    
+2

caseInsensitiveMatch

$routeProvider.when('/clients/new-invoice', 
{     templateUrl: 'templates/new-invoice.html', 
      controller: 'InvoicesController',
      caseInsensitiveMatch: true,
      title: 'New Invoice',
      data: {
      auth: true,
      plevel: [5] 
      }                
});

,

0

, routeProvider. : - preg ( - /uuid " "?), . :

/clients/: clientID = >

/client/: clientID/new-invoice = > new-invoice

/clients/new-invoice = > new-invoice

but it’s good if you are forced to perform routing as described in your example, you need to find another solution, for example, parameters matching parameters.

hope i can help a little hello

0
source

Source: https://habr.com/ru/post/1533728/


All Articles