Aurelia路由器导航和导航ToRoute

TSR*_*TSR 14 aurelia aurelia-navigation aurelia-router

在应用程序中,我希望导航到home/contract-view/10一个动作.试着

this.router.navigateToRoute(`home/contract-view`, { id: 10}, { absolute: true });
Run Code Online (Sandbox Code Playgroud)

失败了 Route home/contract-view not be found

另一个尝试:

this.router.navigate(`#/home/contract-view`, { id: 10});
Run Code Online (Sandbox Code Playgroud)

失败了Route not found: contract-view(…) 如何实现这一目标?App.ts:

configureRouter(config: RouterConfiguration, router: Router) {
        config.title = 'Contracts Portal';
        config.map([
            { route: ['', 'dummy'], name: 'dummy', moduleId: 'dummy', nav: false, title: 'Dummy', settings: { pos: 'left' } },
            { route: 'home', name: 'home', moduleId: 'home', nav: true, title: 'Home', settings:{pos: 'left', class: 'home' }, auth: true },
        ]);
        this.router = router;    
    }
Run Code Online (Sandbox Code Playgroud)

Home.ts:

 configureRouter(config: RouterConfiguration, router: Router) {
        config.map([
            { route: ['', 'contract-view/:id'], name: 'contract-view', moduleId: 'contract-view', nav: true, title: 'Contract' },
            { route:  'doc-view/:id', name: 'doc-view', href:'doc-view', moduleId: 'doc-view', nav: true, title: 'Document' },
        ]);

        this.router = router;
        this.router.refreshNavigation();
    }
Run Code Online (Sandbox Code Playgroud)

wea*_*e08 38

首选解决方案是使用您在路由器中配置的命名路由.

this.router.navigateToRoute('contract-view', {id: 10});
Run Code Online (Sandbox Code Playgroud)

  • 这不适用于子路线。 (2认同)
  • @ weagle08-您能举个例子吗?如果您尝试导航到片段“ users /:id / detail”中的子路线“ detail”,那么您将用什么调用navigateToRoute?大概您必须在子路由器上对其进行调用,以使其无法正常工作,但这并不是很好。 (2认同)

val*_*hek 7

您配置了"home"中的路由器contract-view/:id,因此您需要this.router.navigate('home/contract-view/10').并尝试删除this.router.refreshNavigation()过于