'I can't access page using http-server

I tried to access the page using http-server -p 8081 but the browser said "No webpage was found for the web address: http://localhost:8081/app/home"

I run ng build --prod and go to dist folder and run http-server -p 8081

root-routing.module.ts has

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';

const routes: Routes = [
    { path: '', redirectTo: '/app/home', pathMatch: 'full' },
    { path: 'account', loadChildren: 'account/account.module#AccountModule', data: { preload: true }
},
{
    path: 'app',
    loadChildren: 'app/app.module#AppModule', 
    data: { preload: true }
    }
];

@NgModule({
    imports: [RouterModule.forRoot(routes)],
    exports: [RouterModule],
    providers: []
})
export class RootRoutingModule { }

How can I access my home page? Do I miss anything?



Solution 1:[1]

I found http-server has a problem. I installed [email protected]

Solution 2:[2]

I had the same problem, to my understanding http-server does not supports serving SPA, at least not if you open directly an url to a specific page. Instead it will try to serve the file at the given path. For instance: /home/hello won't be resolved to your angular's router path but instead try to serve /home/hello/index.html which is likely not found

To prevent this issue, I used angular-http-server

npm install -g angular-http-server
cd /path/to/site
angular-http-server

Solution 3:[3]

Maybe you named your project wrongly:

http-server -p 8080 -c-1 dist/<project-name>

Check your dist folder to see what the name of your app is. Most likely just "app".

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 sally
Solution 2 Flavien Volken
Solution 3 Stef Van Looveren