Ad

Adding A Friendly Url In Dynamic Views Of Angular8 To Use SEO

i'm using Angular routing to switch between views.

My version of Angular is "@angular/core": "~8.0.0"

This is how it's done today:

www.mywebsite.com.br

When i chose some view, i load a data from the server to show the info, and the URL look's like this:

www.mywebsite.com.br/course/1

But, to use SEO in my website i need to show the tittle of the course in the URL, like this:

www.mywebsite.com.br/how-to-use-a-computer

And when i navigate inside this course i need to create the path, like this:

www.mywebsite.com.br/how-to-use-a-computer/my-first-class

This, my routes:

const routes = [

  {path: 'manufacturer/:id_ manufacturer', component: ManufacturerComponent},

  {path: 'course/:id_course', component: CourseComponent},

  {path: 'category/:id_ category', component: CategoryComponent},

  {path: 'course/:id_course/class/:id_ class', component: ClassComponent},
];

There is anyway to change the URL?

Ad

Answer

Check your module imports, the # can be disabled by providing { useHash: false } as the second argument of the RouterModule.forRoot:

imports: [
    ...
    RouterModule.forRoot(routes, { useHash: false })  // set it as false to disable the #
]

This is where you probably overridden your LocationStrategy, which defaults to PathLocationStrategy (the one without a hash). The other option is HashLocationStrategy, which behaves as you described it (with a #). You can read more about LocationStrategy in the Angular documentation.

Ad
source: stackoverflow.com
Ad