2
votes

I have an ember application (version 3.14) which I'd like to do a transition to a Route with dynamic segment

I'd like to redirect to /projects/other/2020 when user visits /projects/other I change my projects/other route so it looks like this but it throws me an error

import Route from '@ember/routing/route';

export default Route.extend({
    
    model: function(){
    
    },
    redirect() {
        let year_data = {
            year: '2020'
        };
        this.transitionTo('projects.other',year_data);
    }
});

and this is how my projects route looks like in routes.js

this.route('projects', function() {
  this.route('notable',{path: '/'});
  this.route('other', function() {
    this.route('list', {path: '/:year'});
  });
});

these are the errors from google chrome console box

error screenshot

1
my mistake, i was trying to do a transition to /projects/other/2020 which the route is projects.other.list changing the code to this.transitionTo('projects.other.list',year_data) fixes this. again this is just me being careless for not re-checking the routeRonny Susanto

1 Answers

2
votes

Error message is pretty clear. You are trying to redirect to projects.other.index route which does not have any dynamic segments. Also, according to docs, you need to pass an id and not an object. When you pass an object, ember treats it like ready to use model. So, your code should be

this.transitionTo('projects.other.list', '2020');