路由器无法与参数匹配正确的路由

时间:2017-07-11 03:50:36

标签: dart angular-dart

我的应用程序正在使用HashLocationStrategy。我发现如果两个路由都有参数,则角度路由器无法匹配正确的路由。

我的问题出在我的Dart代码中。路由器只识别/ edit /:id,但无法处理对/ article /:id。

的请求

http://localhost/#/edit?id=xxxxxx(工作)

http://localhost/#/article?id=xxxxxx(不工作)

app_component.dart

@Component(
    selector: 'body[app]',
    templateUrl: 'app_component.html',
    directives: const [ROUTER_DIRECTIVES]
)
@RouteConfig(const [
  const Route(path: '/', name: 'Home', component: HomeComponent, useAsDefault: true),
  const Route(path: '/edit/:id', name: 'Edit', component: EditComponent),
  const Route(path: '/edit', name: 'Edit', component: EditComponent),
  const Route(path: '/article/:id', name: 'Article', component: ArticleComponent),
  const Route(path: '/...', name: 'Auth', component: AuthComponent)
])
class AppComponent {

}

app_component.html

<router-outlet></router-outlet>

更新:问题在route.navigate中得到修复,并直接向浏览器提供URL。

@Component(
    selector: 'body[app]',
    templateUrl: 'app_component.html',
    directives: const [ROUTER_DIRECTIVES]
)
@RouteConfig(const [
  const Route(path: '/', name: 'Home', component: HomeComponent, useAsDefault: true),
  const Route(path: '/edit/:id', name: 'Edit', component: EditComponent),
  const Route(path: '/edit', name: 'Edit', component: EditComponent),
  const Route(path: '/...', name: 'Auth', component: AuthComponent),
  const Route(path: '/article/:id', name: 'Article', component: ArticleComponent),
])
class AppComponent {
    final Location _location;
    final Router _router;
    AppComponent(this._location, this._router);

    @override
    ngOnInit() {
       this._router.navigateByUrl(this._location.path());
    }
}

0 个答案:

没有答案