admin管理员组

文章数量:1345579

I have a router.js file with my configured routes:

routes.js

 export class App {
        configureRouter(config, router) {
        config.title = 'Aurelia';
        config.map([
      {route: ['', `wele`], name: 'wele', moduleId: './wele', nav: true, title:'Wele'},
      {route: 'http', name: 'http', moduleId: './http', nav: true, title:'HTTPTest'},
      {route: 'users', name: 'users', moduleId: './users', nav: true, title:'Github Users'},
      {route: 'plan', name: 'plan', moduleId:'./dp/plan', nav: true, title:'DPTest'},
      {route: 'user_table', name: 'user_table', moduleId:'./dp/user_table', nav: true, title:'Benutzer'}
    ]);

    this.router = router;
  }
}

I want to call one of these routes (plan) from a function in users.js. Do I have to import {Router} in users.js? Or inject?

I have a router.js file with my configured routes:

routes.js

 export class App {
        configureRouter(config, router) {
        config.title = 'Aurelia';
        config.map([
      {route: ['', `wele`], name: 'wele', moduleId: './wele', nav: true, title:'Wele'},
      {route: 'http', name: 'http', moduleId: './http', nav: true, title:'HTTPTest'},
      {route: 'users', name: 'users', moduleId: './users', nav: true, title:'Github Users'},
      {route: 'plan', name: 'plan', moduleId:'./dp/plan', nav: true, title:'DPTest'},
      {route: 'user_table', name: 'user_table', moduleId:'./dp/user_table', nav: true, title:'Benutzer'}
    ]);

    this.router = router;
  }
}

I want to call one of these routes (plan) from a function in users.js. Do I have to import {Router} in users.js? Or inject?

Share Improve this question edited Jul 21, 2016 at 15:16 Tom G. asked Jul 21, 2016 at 10:14 Tom G.Tom G. 411 silver badge4 bronze badges 1
  • please upvote and accept if this helped you – Matthew James Davis Commented Jul 28, 2016 at 15:26
Add a ment  | 

1 Answer 1

Reset to default 13

Either of the following will work

using router.navigateToRoute()

import { Router } from 'aurelia-router';

@inject(Router)
export class UsersViewModel {
  constructor(router) {
    this.router = router;
  }
  doStuff() {
    this.router.navigateToRoute('plan');
  }
}

using native location

export class UsersViewModel {
  doStuff() {
    location.assign('#/users');
  }
}

本文标签: javascriptAureliaio how to navigate to routeStack Overflow