无法在 MEAN STACK 中加载前端路由 Angular 4

Cannot load the front end routing in MEAN STACK with Angular 4

我正在使用 MEAN STACK 和 Angular 4(这项技术的新手)创建一个应用程序。我正在尝试处理前端路由,即在使用 url http://localhost:3000/admin it should load the admin component and http://localhost:3000/registration 时,它应该加载注册组件。

应用程序-Routing.modeule.ts

import {NgModule} from '@angular/core';
import {RouterModule, Routes} from '@angular/router';
import {RegistrationFormComponent} from './registration-form/registration-form.component';
import {AdminFormComponent} from './admin-form/admin-form.component';


const appRoutes: Routes = [
    {path: 'registration', component: RegistrationFormComponent},
    {path: 'admin', component: AdminFormComponent},
    {path: '', redirectTo: '/admin', pathMatch: 'full'}
    //{path: '*', redirectTo: '/registration', pathMatch: 'full'}
];

@NgModule({
    imports: [
        RouterModule.forRoot(appRoutes)
    ],
    exports: [
        RouterModule
    ]
})
export class AppRoutingModule {

}

server.js

app.use('/', express.static(path.join(__dirname, '/dist')));
app.get('/registration', api);
app.get('/admin', api);
app.use('/', api);

router.js

router.get('/registration', function(req, res){
    //res.send('hello world');
   console.log('registration');
});

我有一个 router.js class also.Routing 在我的 angular application.However 中工作正常,当使用带有 angular 的 express 时,我我不是应该如何处理前端 routing.If 它需要通过 router.js 完成 不确定我应该指定什么路径。

我遇到错误:

Error: Cannot GET Pagename

设置静态路径

app.use(express.static(path.join(__dirname, 'dist')));

然后

app.get('*', (req, res) => {
  res.sendFile(path.join(__dirname, 'dist/index.html'));
});

您不需要在服务器端为 angular 应用编写路由