I have built angular project and run it. But localhost doesn't redirect to index.html automatically, I have to manually type localhost:8080/index.html. How can I solve that issue? I have this problem on Windows (angular version is 8), but on Linux and Mac everything work ok.
I have tried change the base href and even delete it, since I found this advice from stackoverflow.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>PsAir</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
App-routing file:
const routes: Routes = [
{
path: routesNames.AUTH,
loadChildren: './auth/auth.module#AuthModule',
canActivate: [AuthGuard]
},
{
path: '',
loadChildren: './main/main.module#MainModule',
canActivate: [AuthGuard],
data: { checkAuth: true }
},
{
path: '**',
redirectTo: '../index.html',
pathMatch: 'full'
}
];
Using angular-http-server instead of http-server solved the problem.
It returns a file if it exists (ex. your-icon.png, index.html), routes all other requests to index.html (rather than giving a 404 error) so that you SPA's routing can take over. The only time it will error out is if it can't locate the index.html file. Read more about angular-http-server here.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.