|
4 | 4 | angular.module(ApplicationConfiguration.applicationModuleName, ApplicationConfiguration.applicationModuleVendorDependencies);
|
5 | 5 |
|
6 | 6 | // Setting HTML5 Location Mode
|
7 |
| -angular.module(ApplicationConfiguration.applicationModuleName).config(['$locationProvider', '$httpProvider', |
8 |
| - function ($locationProvider, $httpProvider) { |
| 7 | +angular.module(ApplicationConfiguration.applicationModuleName).config(['$locationProvider', '$httpProvider', '$urlRouterProvider', |
| 8 | + function ($locationProvider, $httpProvider, $urlRouterProvider) { |
| 9 | + |
| 10 | + // This Rule works for all routes |
| 11 | + $urlRouterProvider.rule(function ($injector, $location) { |
| 12 | + //what this function returns will be set as the $location.url |
| 13 | + var path = $location.path(), normalized = path.toLowerCase(); |
| 14 | + if (path !== normalized) { |
| 15 | + //instead of returning a new url string, I'll just change the $location.path directly so I don't have to worry about constructing a new url string and so a new state change is not triggered |
| 16 | + $location.replace().path(normalized); |
| 17 | + } |
| 18 | + // because we've returned nothing, no state change occurs |
| 19 | + }); |
| 20 | + |
| 21 | + /* |
| 22 | + This route config will cause conflicts |
| 23 | +
|
| 24 | + articles - { url: '/articles', abstract: true } |
| 25 | + articles.list - { url: '' } |
| 26 | + articles.view - { url: '/:articleId' } |
| 27 | +
|
| 28 | + Is the solution to refactor this route config? The below routes won't have the same conflict |
| 29 | +
|
| 30 | + articles - { url: '/articles', abstract: true } |
| 31 | + articles.list - { url: '' } |
| 32 | +
|
| 33 | + article - { url: '/article', abstract: true } |
| 34 | + article.view - { url: '/:articleId' } |
| 35 | +
|
| 36 | + */ |
| 37 | + |
| 38 | + // This Rule won't work with routes that have the above mentioned configuration, |
| 39 | + // but it DOES work when defined directly in the Articles routes config with the same configuration. |
| 40 | + // Why would we see this behavior?? |
| 41 | + |
| 42 | + /*$urlRouterProvider.rule(function ($injector, $location) { |
| 43 | + var path = $location.path(); |
| 44 | + var hasTrailingSlash = path.length > 1 && path[path.length - 1] === '/'; |
| 45 | +
|
| 46 | + if (hasTrailingSlash) { |
| 47 | +
|
| 48 | + //if last character is a slash, return the same url without the slash |
| 49 | + var newPath = path.substr(0, path.length - 1); |
| 50 | + //return newPath; |
| 51 | + $location.replace().path(newPath); |
| 52 | + } |
| 53 | + });*/ |
| 54 | + |
9 | 55 | $locationProvider.html5Mode(true).hashPrefix('!');
|
10 | 56 |
|
11 | 57 | $httpProvider.interceptors.push('authInterceptor');
|
|
0 commit comments