2016-11-25 10 views
0

Angular2アプリケーションをロードする前に(ロードすることなく)ログインページにリダイレクトする必要があります。 私のプロジェクトは、私がuglifyjs条件付きロードAngular2

<script> 
    var cookie = $.cookie(COOKIE_NAME); 
    if (cookie == undefined){ 
     window.location.href = LOGIN_SERVER_URL 
    } else { 
     var head = document.getElementsByTagName('head')[0]; 
     var script = document.createElement('script'); 
     script.src = "build/app/bundle.min.js"; 
     head.appendChild(script); 
     head.innerHTML += ("<script>System.import('app').catch(function(err){ console.error(err); }); <\/script>"); 
    } 
</script> 

後angular2のjsファイルをロードすると、このソリューションが動作するangular2-quicksart

に基づいています。 JSがロードされ、アプリケーションが実行されています。

角度アプリケーションをロードするためにsystemjsファイルを使用すると、systemjs.config.jsがロードされましたが、アプリケーションが実行されません。

`script.src =" systemjs.config.js ";

システムを動的にロードできますか?

答えて

0

これは、システムJSをロードする方法..です

https://github.com/angular/quickstart/blob/master/src/index.html

これは角度クイックスタートプロジェクトから取られています。

私は、コンテキストのために全体のindex.htmlを提供しています:

!DOCTYPE html> 
<html> 
    <head> 
    <title>Angular QuickStart</title> 
    <base href="/"> 
    <meta charset="UTF-8"> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <link rel="stylesheet" href="styles.css"> 

    <!-- Polyfill(s) for older browsers --> 
    <script src="node_modules/core-js/client/shim.min.js"></script> 

    <script src="node_modules/zone.js/dist/zone.js"></script> 
    <script src="node_modules/systemjs/dist/system.src.js"></script> 

    <script src="systemjs.config.js"></script> 
    <script> 
     System.import('main.js').catch(function(err){ console.error(err); }); 
    </script> 
    </head> 

    <body> 
    <my-app>Loading AppComponent content here ...</my-app> 
    </body> 
</html> 

SystemJSはない動的に、フロントをアップロードされます。 System JSの仕事はダイナミックなモジュールローダーですが、System JSがロードされるまでモジュールローダーがないので、System JS自体を動的にロードすることはできません。