NavigateToRoute() not always updating currentInstruction

I am trying to programatically navigate to a new route based on things happening in my javascript, but sometimes the page thinks it’s still on the current page and tries to load things that do not belong, resulting in javascript errors.

How can I update currentInstruction or make navigateToRoute function like I expect? Or am I missing some key component that would prevent this from happening?

Here’s my javascript code where I’m navigating to a new route:

search.js:

this.router.navigateToRoute('customer', params);

        console.log('current navigation', this.router.currentInstruction.config.name);
// when I log this, sometimes it shows 'customer' and sometimes 'search'

app.js

configureRouter( config, router )
  {
    config.title = 'ARIS';
    config.options.pushState = true;
    config.options.root = '/';

    config.map([
      {
        route: '', 
        name: 'home', 
        moduleId: PLATFORM.moduleName('home'), 
        nav: true, 
        title: 'Home',
      },
      {
        route: 'aris', 
        name: 'aris', 
        moduleId: PLATFORM.moduleName('aris'), 
        nav: false, 
        title: 'ARIS',
      },
      {
        route: 'login', 
        name: 'login', 
        moduleId: PLATFORM.moduleName('login'), 
        nav: false
      },
      {
        route: 'customer/:debtor_id?/:inv_num?', 
        name: 'customer', 
        moduleId: PLATFORM.moduleName('customer'), 
        nav: true, 
        href: 'customer',
        title: 'Customer',
        //activationStrategy: activationStrategy.invokeLifecycle,
      },
      {
        name: 'search',
        route: 'search', 
        moduleId: PLATFORM.moduleName('search'), 
        nav: true, 
        title: 'Search/Worklist',
        settings: {dropdown: true}
      },
      ]);

    config.mapUnknownRoutes('home');
    config.fallbackRoute('home');    
    this.router = router;
  }

I tried using activationStrategy, but this didn’t change what was going on, so I commented it out.

Any insight would be appreciated.

Were you able to figure out what you needed? I think I’m in the same situation and would be interested in what you did to get this to work (if you have a solution).

Thanks!

this.router.navigateToRoute('customer', params); should take you to the provided route
console.log('current navigation', this.router.currentInstruction.config.name); right after route navigation will probably be a race condition issue, as the router starts navigating and you don’t wait for navigation to finish.
If you want to perform an action when route navigation completes, there are events for that, see here Understanding Aurelia Router Events - I Like Kill Nerds

I’m not sure I fully comprehend what you’re trying to do, could you elaborate on the functionality you’re trying to achieve?