所以我需要创建一个不需要运行服务器就能工作的版本。Angular 2 ng build
运行ng build
。有一个dist
文件夹。
当我运行index.html
即时得到这样的错误
GET file:///D:/inline.bundle.js net::ERR_FILE_NOT_FOUND
他正在寻找的是js
文件在我的d根://驱动器,而不是在一个项目文件夹
所以没关系,我从我的index.html
去除<base href="/">
和得到这个错误:
Unhandled Promise rejection: No base href set. Please provide a value for the APP_BASE_HREF token or add a base element to the document. ; Zone: <root> ; Task: Promise.then ; Value: ZoneAwareError {__zone_symbol__error: Error: No base href set. Please provide a value for the APP_BASE_HREF token or add a base element to…, __zone_symbol__stack: "Error: No base href set. Please provide a value fo…testing1/dist/vendor.bundle.js:28631:62) [<root>]", __zone_symbol__message: "No base href set. Please provide a value for the A…HREF token or add a base element to the document."} Error: No base href set. Please provide a value for the APP_BASE_HREF token or add a base element to the document.
at new PathLocationStrategy (file:///D:/angular/testing1/dist/vendor.bundle.js:66150:19) [angular]
at provideLocationStrategy (file:///D:/angular/testing1/dist/vendor.bundle.js:62944:9) [angular]
at AppModuleInjector.get (/AppModule/module.ngfactory.js:164:77) [angular]
at AppModuleInjector.get (/AppModule/module.ngfactory.js:169:84) [angular]
at AppModuleInjector.get (/AppModule/module.ngfactory.js:198:151) [angular]
at AppModuleInjector.createInternal (/AppModule/module.ngfactory.js:241:60) [angular]
at AppModuleInjector.NgModuleInjector.create (file:///D:/angular/testing1/dist/vendor.bundle.js:56323:76) [angular]
at NgModuleFactory.create (file:///D:/angular/testing1/dist/vendor.bundle.js:56291:18) [angular]
at file:///D:/angular/testing1/dist/vendor.bundle.js:38426:61 [angular]
at Object.onInvoke (file:///D:/angular/testing1/dist/vendor.bundle.js:28762:37) [angular]
at Zone.webpackJsonp.528.Zone.run (file:///D:/angular/testing1/dist/polyfills.bundle.js:2591:43) [<root> => angular]
at NgZone.run (file:///D:/angular/testing1/dist/vendor.bundle.js:28631:62) [<root>]
所以angular2router
不工作没有<base>
和index.html
找不到我的本地文件与<base>
我该如何解决它?
只需放回 但是。 –