stijn.aerts
stijn.aerts

Reputation: 6206

Extract parameter from route url

I want to give a parameter to an url in Ember.js and extract this parameter in the route index.js.

http://localhost:4200/7698

And then in index.js I do this:

model( params ) {
    console.log( params.edition_id );
    return "something";
}

Router.js file:

Router.map( function( ) {
  this.route( '/index' );
  this.route( '/', {
    path: '/:edition_id'
  } );
} );

This gives me the following error:

Error while processing route: / Ember Data Request GET undefined returned a 404 Payload (text/html; charset=utf-8) Cannot GET /7698 Error: Ember Data Request GET undefined returned a 404 Payload (text/html; charset=utf-8) Cannot GET /7698

However I don't want ember-data interfering with this, I simply need the parameter in my app logic, without any models or such.

Upvotes: 0

Views: 161

Answers (1)

Shayan
Shayan

Reputation: 966

you should just use

Router.map( function( ) {
    this.route('index', { path: '/:edition_id' });
} );

by the way be aware if you remove # from first of url, you would get 404 error on reload your page

Upvotes: 1

Related Questions