Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get params from the url with aurelia

Tags:

aurelia

For example: http://localhost:3000/#/report/123456

How do I get the "123456" part from the url with Aurelia?

Hope you can help me, couldn't find anything useful in the docs.

like image 222
Patrick Avatar asked Apr 22 '16 07:04

Patrick


2 Answers

you can get the submitted params in the activate method of the router (in your viewmodel)

activate(params) {
   return this.http.fetch('contacts/' + params.id)
      .then(response => response.json())
      .then(contact => this.contact = contact);
}

found in a nice blogpost here: http://www.elanderson.net/2015/10/aurelia-routing-with-a-parameter/

like image 192
fops Avatar answered Jan 04 '23 05:01

fops


You have to have a route defined for it:

{ 
    route: ['report/:id'], 
    moduleId: './report', 
    title: 'Report', 
    name: 'report' 
}

Then in your view model, you can get the id from the params object:

activate(params) {  
    console.log(params.id);
}
like image 24
Mike Avatar answered Jan 04 '23 04:01

Mike