4

I can pass a parameter to a route and navigate there using this code:

this.router.navigateToRoute('CaseList', { RefNo: this.selectedData.RefNo
},  { replace: true })

The parameter is passed correctly to the new page.

However, I would like to open the page in a new tab. I've tried:

window.open(this.router.generate('CaseList', { RefNo:
this.selectedData.RefNo }),'_blank');

This opens a new tab and appends the parameter value to the URL e.g. http://localhost:49328/AppCaseMgmt/CaseList/20150000015, but if I try to read the value of the parameter on activation like this:

activate(params) {
    console.log('activate in case list');
    console.log(params.RefNo);
    ....
}   

it's undefined.

I am adding the route dynamically to the router using

this.router.addRoute({
        route: "/AppCaseMgmt/CaseList/:RefNo", name: "CaseList", moduleId: "app/case-management/case-list",
        title: "CaseMgmt:CaseManagement_SiteMapHeaderCaseManagement_title" });
    this.router.refreshNavigation();

but that shouldn't make a difference as far as I'm aware. (I've tried adding the route to the config.map instead but without success). I'm beginning to think this isn't possible. Has anyone any ideas?

Thanks, Anthony

1 Answers1

6

I couldn't reproduce this error. However, I'd like to restore your faith in Aurelia, so here is a working demo with source according to your use case.

I ran into a similar issue before when reusing the same ViewModel, but in that case the activated event had not been called for the second time. I've solved that by changing the VM's activationStrategy to replace according to Cheat Sheet

export class Product {
    determineActivationStrategy(){
        return activationStrategy.replace;
    }
}

This might bring you closer to the solution.

Marton Sagi
  • 1,247
  • 1
  • 8
  • 10
  • Hi Marton. Thanks very much for the working example. It's a great help to know that it's possible. Unfortunately I still haven't got it working in my project. As soon as I have useful information as to why (or how I've fixed it) I'll post it here. – Anthony Armour Sep 02 '16 at 08:59
  • Thats worked for me, but I had to do for all my routes, so I added a option in router definition, explained in this answer: http://stackoverflow.com/a/41683970/815590 – Alberto Monteiro Feb 10 '17 at 14:56