14
votes

In app.ts I am looking to navigate to home/contract-view/10 on a action. Tried

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

fails with Route home/contract-view not be found

Another try:

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

fails with Route not found: contract-view(…) How to achieve this? 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;    
    }

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();
    }
3

3 Answers

39
votes

preferred solution would be to use your named routes that you have configured in the router.

this.router.navigateToRoute('contract-view', {id: 10});
9
votes

You have router in 'home' configured with contract-view/:id, so you need this.router.navigate('home/contract-view/10'). And try to remove this.router.refreshNavigation() too

0
votes

Thanks @valichek, Just had to make it this.router.navigate('/home/contract-view/10') for it to work. That extra / at the beginning made difference.