- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我有一个应用程序,我需要根据用户点击的 URL 重定向到不同的组件,假设如果它是 localhost/login
它应该重定向到路由 localhost/login/#/login
,如果 localhost/user
然后 localhost/user/#/spreadsheet
,这在没有 AOT 的情况下工作正常,但没有 AOT,这是我的函数来获取重定向路由:
export function baseHref() {
return ((document.location.pathname == '/login/') ? 'login' : ((document.location.pathname.split('/')[3] == 'edit') ? 'edit' : ((window.innerWidth >= 720) ? 'spreadsheet' : 'two-panel')));
}
这是我的路线:
export const rootRouterConfig: Routes = [
// If path is not defined it will redirect to spreadsheet
{ path: '', redirectTo: baseHref, pathMatch: 'full' },
{ path: 'spreadsheet', component: ContactParent },
{ path: 'two-panel', component: ContactParent },
{ path: 'login', component: Login },
{ path: 'login/step1', component: LoginStep1 },
{ path: 'login/step2', component: LoginStep2 },
{ path: 'edit', component: EditSingleContact },
{ path: 'share', component: EditSingleContact }
];
这里总是重定向到two-panel
路由
最佳答案
这可以通过使用函数工厂向 ROUTES
提供路由定义来解决...(在 Angular 4.1.2 上测试)
修改您的 AppModule (app.module.ts):
更改导入数组中的 RouterModul.forRoot
imports: [
RouterModule.forRoot(routes)
...
到
RouterModule.forRoot([])
在提供者数组中添加这两个提供者:
... ANALYZE_FOR_ENTRY_COMPONENTS
} from '@angular/core';
... ROUTES,
} from '@angular/router';
...
providers: [
{provide: ANALYZE_FOR_ENTRY_COMPONENTS, multi: true, useValue: routes},
{provide: ROUTES, multi: true, useFactory: getRoutes},
...
定义工厂函数(在 app.module.ts 文件的顶部):
export function getRoutes() {
return routes;
}
也许您还需要创建新文件,例如:app.routes.ts
并将您的路由定义放在那里
export const routes: Routes = [
{
path: '',
...
并将其导入 AppModule (app.module.ts)。
import { routes } from './app.routes';
关于AOT的Angular 4动态路由问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43839949/
我正在尝试从 Unity 发布到我的 iPhone 4s。构建成功,但我继续收到此消息: “在 aot-only 模式下运行时无法加载 AOT 模块‘Assembly-CSharp’,因为依赖项无法找
在听说了这么多有关 Angular AOT 模式的信息后,我想尝试一下。因此,我们将应用程序迁移到 Angular v4.1.2,并进行了所有必要的更改。当我尝试使用我的 webpack 配置文件中的
我有一个 C# 项目,我需要将其编译为 native 二进制文件。我在这里读过: http://www.mono-project.com/AOT Mono 可以将程序集预编译为两个选项之一: --ao
我搜索了很多关于这种伟大语言的信息,并在此页面上找到了自己 https://github.com/dart-lang/sdk/wiki/Snapshots但它没有回答一些问题: 快照和 AOT 有什么
我知道什么是字节码检测。它只是在运行时更改 .class 文件字节码,这似乎从 JDK 1.5 开始可用。但是,据说是在类加载期间而不是运行时。 现在我的问题是,什么是 AOT 或提前检测?相反的程序
我正在为我的应用程序构建一个插件系统。我读到任何人都可以反编译 .class 文件,因此我不得不使用 Ahead-Of-Time 编译器(对吗?)。问题是我需要动态加载一些插件类。现在,我正在将所有
我的问题是 Angular 模块之一无法在 Safari 浏览器中正常工作。 我有以下代码: @NgModule({ bootstrap: [ AppComponent ], impo
我在这里问是因为我无法在网上找到完整的文档。示例 here太简单了。我有一个包含多个组件和一些模块的应用程序。用ngc编译后,我有很多错误。我发现修复它们的方法是使用相对路径。因此,我在所有组件中都使
在使用 webpack 进行 AOT 构建后,bundle 将每个组件模板包含两次,使得 bundle 比需要的大得多,因为模板作为字符串包含在内,UglifyJS 无法缩小。 我希望组件模板被排除为
我正在尝试使用 ngc 编译 angular 2.4.4: Error: Error encountered resolving symbol values statically. Expressio
当我这样做时,有什么原因(我可以解决): ngc -p tsconfig.aot.json 作为回应,它要求: 姓名: ngc 似乎忽略了我的 tsconfig.aot.json。 这可能是什么原因?
我正在开发一个 Angular 7 应用程序,除了加载问题外它工作正常,在研究中我发现我应该使用 AOT 构建而不是 JIT 或正常构建,由于应用程序规模巨大,我无法进行 aot 构建,它正在返回堆我
我在 Dynamics AX 2012 中有一个 AOT 查询,它由 HcmWorker 和 HcmEmployment 表(等等)组成。我的问题是,当我创建报告(不是 SSRS)或以其他方式使用此查
有谁知道在使用带有 AOT 编译的 Angular CLI 时如何获得更详细的错误堆栈跟踪?使用 JIT 编译运行时,我的应用程序没有问题,但是当我运行 ng build --aot 时,我得到的只是
我想查询 AOT 以查看是否存在使用 X++ 的表名。谁能指出我正确的方向或提供一些示例代码来做到这一点? 如果表存在并提供名称 (str tableName),则返回 true;否则,返回false
我有一个 Angular 5 应用程序,当我在测试模式下运行时没有问题,也就是说,当我使用 ng serve 命令在本地运行应用程序时。但是,当我在生产模式下部署应用程序时,即通过命令ng build
语境 我正在创建一个 Angular 应用程序的桌面版本,为此我正在使用 Electron 。 打开主窗口非常简单: win = new BrowserWindow({ width: 1280
我有一个看起来像这样的错误处理程序: @Injectable() export class GlobalErrorHandler implements ErrorHandler { construct
当我尝试构建启用了 AOT 选项的 Android 应用程序时,收到以下错误消息。 Invalid command line switch for "aapt.exe". VersionCode is
我在我的 Angular 2 应用程序中使用 Highcharts 和 Kendo Charts,当我尝试运行 AOT 编译时,它会抛出类似的错误 Cannot Import Module 或 Hom
我是一名优秀的程序员,十分优秀!