title: Remove trailing slashes in Angularjs
body: <p>I found this snippet in one of the other stack overflow questions.</p>
  
  <pre><code>$urlRouterProvider.rule(function($injector, $location){
    let path = $location.path();
    let hasTrailingSlash = path[path.length-1] === '/';
    if(hasTrailingSlash) {
      console.log('coming in the has trailing slash rule function');
      let normalizedPath = path.substr(0, path.length - 1);
      $location.replace().path(normalizedPath);
    }
  });
  </code></pre>
  
  <p>I have some urls in the following forms <code>/school/:id</code>, <code>/school</code>, <code>/:id</code>, <code>/class/:id</code></p>
  
  <p>The above function works perfectly fine if I enter a url in the form <code>/class/121/</code> and it redirects to <code>/class/121</code>, similarly <code>/about-us/</code> redirects to <code>/about-us</code>. But when I enter <code>/school/</code> I get a 404 error. According to this <a href="https://github.com/angular-ui/ui-router/wiki/url-routing" rel="nofollow">https://github.com/angular-ui/ui-router/wiki/url-routing</a> </p>
  
  <blockquote>
    <p>'/user/:id' - Matches '/user/bob' or '/user/1234!!!' or even '/user/' but not '/user' or '/user/bob/details'. The second path segment will be captured as the parameter 'id'</p>
  </blockquote>
  
  <p>So I am guessing it goes to the <code>/school/:id</code> state, note in such a case, <code>$urlRouterProvider.rule</code> is not called. Some sample defined modules</p>
  
  <pre><code>.config(function($stateProvider) {
      'ngInject';
      $stateProvider
          .state('school', {
      hasLefSideMenu: true,
  
              url: '/school/:id',
              templateUrl: '/school/school.html',
              controller: 'SchoolController',
              reloadOnSearch: false,
              controllerAs: 'schoolCtrl'
          });
  })
  
  
  
  .config(function($stateProvider) {
  'ngInject';
  
  $stateProvider
    .state('all-school', {
      hasLefSideMenu: true,
  
      url: '/school',
      templateUrl: '/all-schools.html',
      controller: 'allSchoolsController',
      controllerAs: 'allSchoolsCtrl'
    });
  </code></pre>
  
  <p>})</p>
  
  <p>Ideally for all urls trailing slash should be removed. Any help would be great</p>