⚠️ This lesson is retired and might contain outdated information.

Map a Second Angular Route to a Component

John Lindquist
InstructorJohn Lindquist
Share this video with your friends

Social Share Links

Send Tweet
Published 8 years ago
Updated 8 months ago

Mapping Angular routes to components is fairly straight-forward, but if you’re not going to lazy load in modules, then you’ll need to make sure to reference each Component you’re using in your main App Module.

[00:00] I'll create a second component in a folder called contacts. I'll say contacts.component.ts. This will just be a component with a template, this is a ContactsComponent. We'll export the class, ContactsComponent.

[00:17] Inside our app routes, just create another path. I'll duplicate this one. We'll say the path here is Contacts. When we hit Contacts, we want to load the ContactsComponent. We also need to declare in my AppModule the ContactsComponent.

[00:33] Now, I'm going to hit Save. I'll let this refresh and then I'll go to /contacts. Hit Enter. You see this is the ContactsComponent. If I go back to the route, you'll see that this is the HomeComponent.

egghead
egghead

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today