2

I'm new to angular. I have a question. localhost:4200/product working but localhost:4200/Product not working. I try;

import { DefaultUrlSerializer, UrlTree } from '@angular/router';

    export class LowerCaseUrlSerializer extends DefaultUrlSerializer {
        parse(url: string): UrlTree {
        return super.parse(url.toLowerCase()); 
        }
    }
    .

    .

    .


      providers: [
            {
                provide: UrlSerializer,
                useClass: LowerCaseUrlSerializer
            }
        ],

but make all the letters small. I want to all the links to work.

/product

/Product

/PRODUCT

/pRoDucT

......

app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { RouterModule, Route } from '@angular/router';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
import { ProductComponent } from './product/product.component';
import { HomeComponent } from './home/home.component';

const routeConfig: Route[] = [
{
  path: '',
  component: HomeComponent
},
{
  path: 'product',
  component:  ProductComponent
}
];

@NgModule({
  declarations: [
    AppComponent,
    ProductComponent,
    HomeComponent
],
  imports: [
    BrowserModule, FormsModule, RouterModule.forRoot(routeConfig)
  ],
  providers: [],

app.component.ts

import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'Title';
}

I hope you understand. Sorry for my bad english.

2

1 Answer 1

2

you should add this provide statement ,

providers: [
            {
                provide: UrlSerializer,
                useClass: LowerCaseUrlSerializer
            }
        ],

to the app.module.ts file. you have the providers empty in the app module.

Sign up to request clarification or add additional context in comments.

3 Comments

the code works but I do not want all the letters to be small.
will this also Serialize the query parameters?
this will change the token in query string

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.