0

In Angular 2, using the tags <nav>, <a> (with the attribute 'routerLink') and <router-outlet> I am able to dinamically show a component surrounded by the one I was into before (for example) activating the toggle to perform this operation.

My browser will also show a link responding to the path I declared in the Routes array inside the app module.

But how can I generate e.g. a button which will bring me in a totally different view (written in a different component) that will likely have nothing in common with the one it comes from?

Thank you.

2
  • That's what the router-outlet is for -- routing to a completely different view. Can you add your code? Sounds like you may have a misunderstanding about component architecture here Commented Aug 11, 2017 at 17:48
  • I think you currently lack some angular basics. I would strongly recommend you to at least check the tutorials in the angular.io page Commented Aug 11, 2017 at 17:59

1 Answer 1

2

The Angular router will do that for you. You just need to set up your routes and router outlets correctly.

Here is a picture of what I think you are asking about:

enter image description here

So your app component would have a router outlet and nothing else. You can then route to any component to take up the entire page.

You can then define a "main component" that has your header and footer and other elements you want to have appear on all of the other pages. That component also has a router outlet.

If you want a page to appear without any header or footer you route to the app component's router outlet.

If you want a page to appear with the header and footer, you route to the main component's router outlet.

Sign up to request clarification or add additional context in comments.

1 Comment

As others have suggested, you may want to learn more about routing either in the tutorial at: angular.io or I have a Pluralsight course on routing here: app.pluralsight.com/library/courses/angular-routing/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.