dimanche 21 avril 2019

Correcting Invalid Route Naming

I'm currently working on a CRUD application - so far I've created an index route, a show route and and create route and have moved on to creating an update method. I've gone ahead and added a route, template and a controller, but whenever I try to click on a link to my new template I receive an error letting me know the following:

"This link-to is in an inactive loading state because at least one of its parameters presently has a null/undefined value, or the provided route name is invalid."

I'm linking to the update path through the show page and can confirm that the ID I'm passing into the link-to function exists. This being the case, I think that there's something likely wrong with my route name but can't figure out where I'm going wrong. I assume it's likely something wrong with the nested routes.

I've tried altering the order of my routes and have put console log statements in the controller I anticipated hitting once the link-to statement was hit - so far I haven't entered the controller.

app/router.js

import EmberRouter from '@ember/routing/router';
import config from './config/environment';

const Router = EmberRouter.extend({
  location: config.locationType,
  rootURL: config.rootURL
});

Router.map(function() {
  this.route('about');
  this.route('contact');
  this.route('posts', function() {
    this.route('post');
    this.route('show', { path: '/:post_id' });
    this.route('edit', { path: '/:post_id/edit' })
    this.route('destroy', {path: ':post_id/destroy'});
  });
});

export default Router;


apps/routes/posts/edit.js

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

export default Route.extend({
    model(params) {
        console.log('hit this when edit route is hit')
        return this.store.findRecord('post', params.post_id);
      }
});

app/templates/post/show.hbs

<div class="jumbo show-posts">
 ...
</div>

   <div class="col-sm-offset-2 col-sm-10">
        <h3>Update post</h3>
   </div>





Aucun commentaire:

Enregistrer un commentaire