데이터베이스는 'dist'디렉토리에서 모듈을로드해야하는 URL을 저장합니다.
{
"personal-area": "js/compile-module.js",
"product": "js/compile-module2.js"
}
적용 예 :
http://localhost:8282/#/personal-area
그런 다음 애플리케이션 lazy (async | dynamic | any)는 다음에서 모듈을로드합니다.
http://localhost:8282/js/compile-module.js
모듈은 사전에 미리 컴파일되어 있으며 메인 애플리케이션을 빌드하는 단계에서는 참여하지 않기 때문에 각도 모듈의 소스에 대한 경로가 없습니다.
라우팅이있는 파일 (app.routers.ts)에 구성 요소 핸들러를 저장합니다.이 핸들러는 데이터베이스에서 서버의 모듈 파일 경로 (URL 기반)를 가져옵니다.
export const ROUTES: Routes = [
{
path: '**',
component: WorkspaceOutletComponent
},
];
메인 핸들러에는 모듈을로드하려고 시도하는 메소드가 있지만 이해가 안되는 이유로 Angular가 독수리를 위해 컴파일 된 모듈을 연결하고 작동하도록하는 방법을 모릅니다.
@Component({ ... })
export class WorkspaceOutletComponent {
constructor() {
}
ngOnInit() {
// detect routing and exec init
}
public init(workSpaceUrl: string, workSpacePathModule: string) {
console.log(`url: ${workSpaceUrl} path: ${workSpacePathModule}`);
this.router.resetConfig([
{
path: workSpaceUrl, loadChildren: workSpacePathModule
}
]);
this.router.navigate([workSpaceUrl])
.then(() => console.log('Navigate to'))
.catch((e) => console.error('Error', e));
}
}
응용 프로그램은 webpack 2를 사용하여 구축되었습니다. 그러나 라우팅을 교체 할 때 그는 저에게 실수를 썼고, 모듈을 동적으로로드하기 위해 어디를 파야할지조차 모릅니다 (데이터베이스에서 가져와야합니다). 어셈블리 중에 모듈에 대한 참조를 알지 못합니다. 소스 코드도 없기 때문에 런타임에로드하려면 타사 모듈이 필요합니다. 내가 도대체 뭘 잘못하고있는 겁니까?
SystemJS를 사용하는 경우. 또한 도움이되지 않고 디스크 (소스에서)에서 모듈을로드하려고합니다.
this.router.resetConfig([
{
path: workSpaceUrl, loadChildren: SystemJS.import(workSpacePathModule).then(function (m) {
console.log(m);
})
}
]);
다음은 모듈로드가 작동하는 방식에 대해 설명합니다. https://github.com/angular/angular-cli/issues/4234#issuecomment-275345763
Do I understand correctly that Angular needs an exact name so that he compiles a hash map. And that's why you can not pass it as I do it, but what should I do if I do not know the correspondence between the path on the disk (since I do not have source codes)?
Not sure whether the reset route way will work or not, but I know that you'll need to generate lazy routes for all modules you might use.
The value for loadChildren
will have to be a static string
. You cannot even call a function in there to get that string
. Even that confuses the Angular CLI magic that works with Webpack to generate the lazy routes.
It should be fine to generate all like lazy routes anyway, and then in runtime load the one(s) you are interested in. Just be careful that resetConfig
could be resetting the whole config.
또한 linkNgModuleFactory
모듈 팩토리의 인스턴스 (Angular가 브라우저 또는 AoT에서 컴파일 한 후 모듈에서 생성하는 것)를 얻을 수 있으며, NgComponentOutlet
.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다