0

I'm tearing my hair out trying to figure out why I'm not passing step 12 of the LWC Specialist superbadge. The error I'm receiving is:

We can’t find the correct settings for navigateToRecord() in the component boatReviews controller. Make sure the component was created according to the requirements, navigating to the standard record page, based on record Id, in view mode, using the proper case-sensitivity and quotation.

My code consists of the following:

<a data-record-id={boatReview.CreatedBy.Id} title={boatReview.CreatedBy.Name} onclick={navigateToRecord}>{boatReview.CreatedBy.Name}</a>
    // Helper method to use NavigationMixin to navigate to a given record on click
    navigateToRecord(event) {
      const recordId = event.target.getAttribute("data-record-id");    //have tried with and without this line
      event.preventDefault();                                          //have tried with and without this line
      event.stopPropagation();                                         //have tried with and without this line
      this[NavigationMixin.Navigate]({
          type: "standard__recordPage",
          attributes: {
              recordId: recordId,                                      //have tried directly calling event.target.getAttribute instead of referencing a variable
              actionName: "view"
          }
      });
    }

Some other things I have tried include switching between single/double quotes, exposing the method as public (thinking maybe they needed to instantiate/test it for some reason), and more. The navigation WORKS - nothing is wrong with this from a functional perspective, which is what makes this so frustrating. Any ideas?

  • try to use event.currentTarget.getAttribute("data-record-id"); – Klecool Jul 1 at 14:16
  • That did not solve it. I tried with a seperate variable, as well as directly calling event.currentTarget.getAttribute in the navigationMixin settings. – Curious Blueprints Jul 1 at 14:20
  • you do not need to add objectApiName in NavigationMixin.Navigate? – Klecool Jul 1 at 14:22
  • Not when navigating to a record. It doesn't hurt anything (I just checked), but there is no difference in behavior or in the "Check Challenge" button. – Curious Blueprints Jul 1 at 14:26
7

The trailhead challenge in this case expects you to use event.target.dataset.*

Both event.target.getAttribute and event.target.dataset are correct but its just a stupid time consuming test.

This one should pass the test

    navigateToRecord(event) { 
      this[NavigationMixin.Navigate]({
        type: "standard__recordPage",
        attributes: {
            recordId: event.target.dataset.recordId,
            actionName: "view"
        }
      });
    }
| improve this answer | |
  • This is the kind of thing that makes Superbadges incredibly frustrating - especially when there is no indication they want you to use that specific method. This worked though, thank you so much! – Curious Blueprints Jul 1 at 15:15

Not the answer you're looking for? Browse other questions tagged or ask your own question.