Search code examples
htmlangularangular2-routing

Angular2 without hash in the url


Now, my website's url looks like this because I'm using the approach described here

http://localhost:4200/#/cadastro

Is it possible to remove the hash in the url and not get the 404 error?

EDIT: Router Module added

const appRoutes: Routes = [
    { path: '', component: HomeComponent },
    { path: 'cadastro', component: CadastroNoivosComponent },
    { path: '**', component: HomeComponent }
];

export const routing = RouterModule.forRoot(appRoutes);

Solution

  • If you use PathLocationStrategy as describe here you can remove the hash in the URL.

    But getting rid of 404 error needs some server side tweak. A quick and easy way is to configure your server to load the home page when any URL of the form http://yourhost/* is requested.