3

I've done Angular's hero tutorial and have a basic understanding of routing. However, that seems to only route part of the page (functioning like some kind of iframe).

If I'm looking to basically route index.html, i.e. doing the traditional <a href> to another location (changing the entire page) how would I go about it?

In other words, if index.html contains <my-app></my-app> is it possible to have another component to have its selector as my-app also and have it called when an event occurs?

1
  • 1
    Angular2 is for creating single page applications, instead of redirecting to a new page you change the components displayed on the current page Commented Dec 7, 2016 at 6:14

1 Answer 1

2

That's not how routing is supposed to work and also HTML5 pushState itself doesn't support that. If you load a different page than index.html you're leaving the Angular2 application and loading an entirely different application. That's not what routing is about.

Angular2 is for SPA where the application is loaded and then the view is updated according to routing and component state, instead of reloading a page from the server after each or some user actions.

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

4 Comments

Ah. I've read around and I can do child routing right? That means I can do routing on my main Cars page, then if someone needs to go to another differently formatted page (say Trains) They route to that, which then has child routes, which changes the looks of the Trains outlook.
Not sure what you mean. In Angular2 you don't have pages, you have components and the current route defines what components are shown on the screen while staying within the same page.
Can you have a router link that's within the router-outlet tags? So that when you click on the link, it will change the entire look/component. Because in the heroes tutorial the nav bar is always the same and unchanged. I'm just wondering if there's a way to simulate changing web pages.
You can have a root component AppComponent with 100% with and height and no border/padding and only a <router-outlet></router-outlet> in the template and then routes that add different components inside the router-outlet depeding on the selected route. The components added by the router can have routerlinks to navigate to other routes.

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.