将服务静态文件重定向到 root,html5 路由,angular2
Redirect serving static files to root, html5 routing, angular2
我正在构建一个 Angular 2 应用程序并且我正在使用 html5 路由。
我偶然发现了嵌套路由的问题。问题是,当我定义 /route1
时,它工作正常,但在 /route1/child-route
的情况下,它不起作用。
我使用 browserSync
来提供文件,我使用中间件重定向到 index.html。到目前为止,我已经看到问题出在编译的 TypeScript 文件和使用相对 URL 的 SystemJS 上,例如,当请求 app.js
时,服务器正在寻找位于 /route1/app.js
位置的文件。谁能帮我解决这个问题?
https://angular.io/docs/ts/latest/guide/router.html
Add the base element just after the <head>
tag. If the app
folder is the application root, as it is for our application, set the href
value exactly as shown here.
<base href="/">
或者添加
import {provide} from 'angular2/core';
import {APP_BASE_HREF} from 'angular2/router';
bootstrap(AppComponent, [
ROUTER_PROVIDERS,
provide(APP_BASE_HREF, {useValue : '/' });
]);
在你的 bootstrap.
我正在构建一个 Angular 2 应用程序并且我正在使用 html5 路由。
我偶然发现了嵌套路由的问题。问题是,当我定义 /route1
时,它工作正常,但在 /route1/child-route
的情况下,它不起作用。
我使用 browserSync
来提供文件,我使用中间件重定向到 index.html。到目前为止,我已经看到问题出在编译的 TypeScript 文件和使用相对 URL 的 SystemJS 上,例如,当请求 app.js
时,服务器正在寻找位于 /route1/app.js
位置的文件。谁能帮我解决这个问题?
https://angular.io/docs/ts/latest/guide/router.html
Add the base element just after the
<head>
tag. If theapp
folder is the application root, as it is for our application, set thehref
value exactly as shown here.
<base href="/">
或者添加
import {provide} from 'angular2/core';
import {APP_BASE_HREF} from 'angular2/router';
bootstrap(AppComponent, [
ROUTER_PROVIDERS,
provide(APP_BASE_HREF, {useValue : '/' });
]);
在你的 bootstrap.