2016-09-28 4 views
0

ディープリンクは、このmy-domain.com/my-appname/aRouteのようなURLをリクエストすると動作しますが、my-domain.com/my-appname/aRoute/ system.jsにアクセスするとここにmy-domain.com/my-appname/aRoute/app/main.jsがある場合は、my-domain.com/my-appname/app/main.jsにあるmain.jsファイルを探します。生成され、角度のない負荷。Angular2 Deep Linkingの問題

<script> 
     // this function is needed to dynamically determine the root url 
     // the angular2 router uses this to support deep linkinkg. 
     function getDocumentBase() { 
      let loc = document.location.href; 
      let locLower = loc.toLowerCase(); 

      let ind = locLower.indexOf('myappnamehere/') 

      let newLoc = loc.substring(0, (ind + 14)); 
      return newLoc; 
     } 
     document.write('<base href="' + getDocumentBase() + '" />'); 
    </script> 

それがsystem.jsようだ:ここで

は私が動的にこのように私のベースのルート要素を設定していsystem.js

<script> 
    System.import('app') 
     .catch(function (err) { console.error(err); }); 

</script> 

で私のアプリをインポートしようとする方法でありますアプリケーションモジュールをロードしようとしているときに、基本要素をアプリのルートとして使用しません。

答えて

0

私はsystemjsの何も知らないことが問題だったことが判明しました。私は次のように私のsystemjs.config.jsファイルを変更する必要がありました:

(function (global) { 
    System.config({ 

     baseURL: getDocumentBase(), 
     paths: { 
      // paths serve as alias 
      'npm:': 'Scripts/npmlibs/' 
     }, 
     // map tells the System loader where to look for things 
     map: { 
      // our app is within the app folder 
      app: 'app', 
      // angular bundles 
      '@angular/core': 'npm:@angular/core/bundles/core.umd.js', 
      '@angular/common': 'npm:@angular/common/bundles/common.umd.js', 
      '@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js', 
      '@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js', 
      '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js', 
      '@angular/http': 'npm:@angular/http/bundles/http.umd.js', 
      '@angular/router': 'npm:@angular/router/bundles/router.umd.js', 
      '@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js', 
      // other libraries 
      'rxjs': 'npm:rxjs', 
      'angular2-in-memory-web-api': 'npm:angular2-in-memory-web-api', 
      'lodash': 'npm:lodash/lodash.js' 
     }, 
     // packages tells the System loader how to load when no filename and/or no extension 
     packages: { 
      app: { 
       main: './main.js', 
       defaultExtension: 'js' 
      }, 
      rxjs: { 
       defaultExtension: 'js' 
      }, 
      'angular2-in-memory-web-api': { 
       main: './index.js', 
       defaultExtension: 'js' 
      }, 
      'lodash': { defaultExtension: 'js' } 
     } 
    }); 
})(this); 

重要な部分は、ベースURLを設定して、それは私のindex.htmlファイルでこの関数を呼び出します:

<script> 
    // this function is needed to dynamically determine the root url 
    // the angular2 router uses this to support deep linkinkg. 
    function getDocumentBase() { 
     let loc = document.location.href; 
     let locLower = loc.toLowerCase(); 

     let ind = locLower.indexOf('my-app-name-here/') 

     // trim off anything after appname as that is truely the root of the app (its a deep link to a route) 
     let newLoc = loc.substring(0, (ind + 17)); 
     return newLoc; 
    } 
</script> 

、その後、私が使用しますこのような基本要素をレンダリングするために、その同じ機能:

<script> 
    document.write('<base href="' + getDocumentBase() + '" />'); 
</script> 
+0

私はディープリンクがsystemjsと一緒に働くだろうかわからないので、Imは一種の、角度のウォークスルーは、あなたがbaseUrlには設定されていません驚い – cobolstinks