In my case I want to support same url in case insensitive manner.
Example: it should support all url
localhost:1029/documentation
localhost:1029/DOCUMENTATION
localhost:1029/DOCUMENTAtion
localhost:1029/docuMENTATION
The routes in Angular are case sensitive. In the routeconfig, you have specified the url path as "product".
It may surprise you but, yes, URLs are case sensitive. And, if you have both upper- and lowercase versions of your site's domain, you may be unintentionally making Google's job harder — and hurting your site's own performance.
That's because the routes that are configured using UI-Router are case sensitive. To make route insensitive, all you have to do is to inject $urlMatcherFactoryProvider service into the config() function and call caseInsensitive(true) function. Let's go back to our Controller.
pathMatch = 'prefix' tells the router to match the redirect route when the remaining URL begins with the redirect route's prefix path. Ref: https://angular.io/guide/router#set-up-redirects. pathMatch: 'full' means, that the whole URL path needs to match and is consumed by the route matching algorithm.
You should add this provide statement to the app.module.ts
import { DefaultUrlSerializer, UrlTree } from '@angular/router';
export class LowerCaseUrlSerializer extends DefaultUrlSerializer {
parse(url: string): UrlTree {
// Optional Step: Do some stuff with the url if needed.
// If you lower it in the optional step
// you don't need to use "toLowerCase"
// when you pass it down to the next function
return super.parse(url.toLowerCase());
}
}
And
@NgModule({
imports: [
...
],
declarations: [AppComponent],
providers: [
{
provide: UrlSerializer,
useClass: LowerCaseUrlSerializer
}
],
bootstrap: [AppComponent]
})
You need a UrlSerializer as follow:
import { DefaultUrlSerializer, UrlTree } from '@angular/router';
export class LowerCaseUrlSerializer extends DefaultUrlSerializer {
parse(url: string): UrlTree {
return super.parse(url.toLowerCase());
}
}
And then added it as a provider in the app.module.ts
providers: [
{
provide: UrlSerializer,
useClass: LowerCaseUrlSerializer
}
]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With