Tomas Marik
Tomas Marik

Reputation: 4093

Angular: 404 Error Page when accessing route

I have angular app (with spring boot on backend)

here are my routes:

export const routes: Routes = [
{ path: '', redirectTo: 'intro', pathMatch: 'full' },
{ path: 'home', component: HomeComponent },


// LANGUAGES
{ path: 'english', component: LanguageComponent },
{ path: 'spanish', component: LanguageComponent },

// CITIES
{ path: 'alexandria', component: CityComponent },
{ path: 'ankara', component: CityComponent }];

export const router: ModuleWithProviders = RouterModule.forRoot(routes, { useHash: false, initialNavigation: true });

And now the funny behavior:

When I route in the app ( = clicking the button/link tags having routerLink ) everything works ok, but when I directly insert url into the browser, I got following:


When I run the frontend on a separate server (localhost:4200), everything works as expected.

Upvotes: 1

Views: 1243

Answers (1)

Milad
Milad

Reputation: 28592

You must configure your spring boot to redirect everything to index.html.

Because when the request hits your server, unless you redirect to angular app (index.html), Angular app won't run, then your routing configuration in Angular isn't worth.

Upvotes: 1

Related Questions