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?
- please upvote and accept if this helped you – Matthew James Davis Commented Jul 28, 2016 at 15:26
1 Answer
Reset to default 13Either 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');
}
}