HashLocationStrategyを使用して、角度2のダーツページをリフレッシュすると、まったく同じビューが表示されるため、正常に動作します。Angular2-Dart PathLocationStrategy
PathLocationStrategy(index.htmlを提供するように設定されたTomcatサーバーを使用)を使用してページを更新すると、パラメータなしのurlで動作しますが、パラメータ付きurlでは機能しません。
はlocalhost:8090/MENU1 //リフレッシュが動作します
はlocalhost:8090/MENU2/paramVal //更新されません
Tomcatのweb.xmlの持つ
<error-page>
<error-code>404</error-code>
<location>/index.html</location>
</error-page>
main.dart
main() {
bootstrap(AppComponent, [
ROUTER_PROVIDERS,
provide(APP_BASE_HREF, useValue: '/')]);
}
app_component.dart
import 'package:angular2/core.dart';
import 'package:angular2/router.dart';
import 'package:angular2/angular2.dart';
import 'package:mboxes/menu1.dart';
import 'package:mboxes/menu2.dart';
@Component(
selector: 'my-app',
templateUrl: 'app_component.html',
directives: const [ROUTER_DIRECTIVES],
providers: const[ROUTER_PROVIDERS, ])
@RouteConfig(const [
const Route(
path: '/menu1',
name: 'Menu1',
component: Menu1Component,
useAsDefault: true),
const Route(
path: '/menu2/:param', name: 'Menu2', component: Menu2Component)
])
class AppComponent {}
代わりに、私はあなたが設定したいと思いますindex.htmlを提供するために
404
を使用しての
app_component.html
<div class="container">
<nav>
<ul>
<li>
<a [routerLink]="['Menu1']">Menu1</a>
</li>
<li> <a [routerLink]="['Menu2', {'param':'paramVal'}]">Menu2</a> </li>
</ul>
</nav>
<div style="padding-left: 200px; padding-top: 200px; padding-bottom: 50px">
<router-outlet></router-outlet>
</div>
</div>
menu1.dart
import 'package:angular2/core.dart';
import 'package:angular2/router.dart';
@Component(
selector: 'menu1',
template: ''' menu 1 was clicked '''
)
class Menu1Component {}
menu2.dart
import 'package:angular2/core.dart';
import 'package:angular2/router.dart';
@Component(
selector: 'menu2',
template: ''' menu 2 was clicked'''
)
class Menu2Component implements OnInit {
final RouteParams _routeParams;
Menu2Component(this._routeParams);
ngOnInit() {
var val = _routeParams.get('param');
print ("passed param is " + val);
}
}
アプリケーションはルートフォルダで提供されますか、または「heros」詳細フォルダです。通常、 'PathLocationStrategy'(デフォルト)を設定し、存在しないURLへのリクエストを' index.html'に書き換える以外は何もしません。 –
私は2つのフォルダしか持っていません - ウェブフォルダにはindex.htmlがあり、libフォルダには他のすべてのコンポーネントが含まれています – marcg
アプリケーションはルートフォルダから提供されています。パラメータのあるURLは更新されません。パラメータをリフレッシュしないURLは問題ありません。 – marcg