Reputation: 69
In the application there is a route defined:
const routes: Routes = [
{ path: '', component: MainComponent },
{ path: 'users', component: UsersComponent }
]
In index.html the base href is also correctly defined.
<base href="/">
When navigating through application the routes are loaded correctly.
But when users enters .../users
directly through the browser the application is not loaded and returns 404. Also when the users refresh the webpage (F5), the application is also not loaded.
Is there something wrong with angular code or server configuration?
Upvotes: 1
Views: 390
Reputation: 4353
It depends on your server setup.
You need to either set up a redirect to index.html
for when a 404 occurs,
Or set up a rewrite so that every request after a certain path always leads to index.html
,
Or simply change the location strategy to hash instead of HTML5 (although not what I'd recommend for a few reasons, as Peter said).
Upvotes: 2