Search code examples
aurelia

How can I redirect to another view-model in Aurelia JS?


I'm writing an application using Aurelia JS. How can I redirect to another URL? Is there a way to do it without creating a whole new navigation pipeline step?

Thanks


Solution

  • to do that inject the router in the ViewModel and use the method navigate(route)

    here is an example:

    import {Router} from 'aurelia-router';
    
    export class MyVM {
    
      static inject() { return [Router]; }
    
      constructor(router){
        this.router = router;
      }
    
      someMethod(){
        this.router.navigate("myroute");
      }
    }