我有以下路线定义.
export const Routes = RouterModule.forChild([
{
path: 'login',
component: LoginComponent
},
{
path: 'protected',
canActivate: [AuthGuardService],
component: ProtectedComponent
},
{
path: 'home',
component: HomeComponent,
canActivate: [AuthGuardService],
},
]);
Run Code Online (Sandbox Code Playgroud)
AuthGuardService如果用户未登录,我已成功实施限制对受保护路由的访问.
我想要实现的是,如果用户已经登录并访问了登录路由,我希望它重定向到主页等其他路由.
我有以下路线定义:
export const AppRoutes = RouterModule.forRoot([
{
path: '',
canActivate: [AuthGuardService],
component: HomeComponent,
children: [
{
path: 'child1',
component: Child1Component
},
]
},
]);
Run Code Online (Sandbox Code Playgroud)
路由会child1从其父级继承 canActivate 防护吗?
我的角度应用程序中有一个 app.config.ts ,看起来像这样:
export const APP_CONFIG = {
....
}
Run Code Online (Sandbox Code Playgroud)
这是在 webpack 构建时生成的。
现在我有不同的角度模块,它们位于我的角度应用程序正在使用的单独存储库中。其中一些模块还需要 app.config.ts 中定义的环境配置。我正在使用 NPM 安装这些模块,因此它们可以在文件夹中找到node_modules。
我的问题是如何在不创建对应用程序本身的依赖项的情况下向这些模块提供环境配置?
我正在考虑将配置保存到全局变量或在应用程序引导时将其保存到 localStorage。
我还应该在每个模块上创建环境配置吗?然后在 webpack 构建上处理它?
任何想法将不胜感激。
在我的 Angular 项目中,我需要在 index.html 文件中使用 PHP。我已经将其重命名为index.php 并更新了 angular.json 以在索引属性中使用index.php。
我的问题是,运行ng build命令后,dist 目录中生成的index.php 文件中的PHP 代码被注释。
<!--?php
$websiteCode = getenv('SITE_CODE');
?--><!DOCTYPE html><html lang="en"><head>
<meta charset="utf-8">
<title>ClientPortal</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<link rel="stylesheet" href="styles.31d6cfe0d16ae931b73c.css"></head>
<body>
<!--?=$websiteCode?-->
<app-root></app-root>
<script src="runtime.f3b55109ab97bda870bd.js" defer></script><script src="polyfills.a58f45ef9ccddb12523d.js" defer></script><script src="main.6629fcd1d3960ef0deb9.js" defer></script>
</body></html>
Run Code Online (Sandbox Code Playgroud)
是否有我需要更新或指定的配置,以便 PHP 代码不会被注释?我正在使用 Angular 12。这在我现有的使用 Angular 7 的 Angular 项目中运行良好。