【发布时间】:2020-11-29 06:37:53
【问题描述】:
我有一个 Angular Universal 项目,它使用 ssr 的 firebasecloud 连接到 firebase。 当我尝试转到路由中不存在的页面时,我收到 403 错误,它不会让我回到正确的页面。 我看到这个页面
这些是我的文件: server.ts:
export function app() {
const server = express();
const distFolder = join(process.cwd(), 'dist/ricicla-risparmia-rinnova/browser');
const indexHtml = existsSync(join(distFolder, 'index.original.html')) ? 'index.original.html' : 'index';
// Our Universal express-engine (found @ https://github.com/angular/universal/tree/master/modules/express-engine)
server.engine('html', ngExpressEngine({
bootstrap: AppServerModule,
}));
server.set('view engine', 'html');
server.set('views', distFolder);
// Example Express Rest API endpoints
// server.get('/api/**', (req, res) => { });
// Serve static files from /browser
server.get('*.*', express.static(distFolder, {
maxAge: '1y'
}));
server.get('*', (req, res) => {
res.render(indexHtml, {req, providers: [{provide: APP_BASE_HREF, useValue: req.baseUrl}]});
});
return server;
}
app-routing.module.ts:
const routes: Routes = [
{path: '', redirectTo: 'home', pathMatch: 'full'},
{path: 'home', component: HomeComponent},
{path: 'login', canActivate: [AuthAdminGuard], component: LoginComponent},
{path: 'articolo', loadChildren: () => import('./components/articolo/articolo.module').then(m => m.ArticoloModule)},
{path: 'admin', canActivate: [AuthAdminGuard], loadChildren: () => import('./admin/admin.module').then(m => m.AdminModule)},
{path: '404', component: NotFoundComponent},
{path: '**', redirectTo: '404'}
];
【问题讨论】:
标签: angular server-side-rendering angular-universal