好吧,事實證明我對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>
林種驚訝的角度演練沒有你設置的baseUrl,因爲我不知道怎麼會deeplinking結合工作與systemjs – cobolstinks