0

I'm beginner to Angular 4, I have issue with trailing slash in ng-2 ui-router-2.

when i hit this url, its works fine

http://localhost:8000/dashboard/home

but by adding / at end, it does not display page

http://localhost:8000/dashboard/home/

I searched it, but found solution for ui-router 1, one of solution was to use

$urlMatcherFactoryProvider.strictMode(false);

and some one said to add rule like this

  $urlRouterProvider.rule(function($injector, $location) {

var path = $location.path();
var hasTrailingSlash = path[path.length-1] === '/';

if(hasTrailingSlash) {

  //if last charcter is a slash, return the same url without the slash  
  var newPath = path.substr(0, path.length - 1); 
  return newPath; 
}});

How i will do this in Angular 4 using ng2 ui-router-2??

1 Answer 1

1

That is configured using the UrlService. Add some code to your router config function which sets the strictMode.

https://ui-router.github.io/ng2/docs/latest/interfaces/url.urlconfigapi.html#strictmode

export function routerConfig(router: UIRouter) {
  router.urlService.config.strictMode(false);
}

@NgModule({
  imports: [        
    UIRouterModule.forRoot({ config: routerConfig })
  ]
}) export class AppModule {}
Sign up to request clarification or add additional context in comments.

1 Comment

Chris can you please tell me where to place this code?? In State.ts file or module ts. As i'm beginner , so i could not get it where to place it

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.