如何不重新加载组件Angular

问题描述 投票:0回答:1

我在app.component.html中有一个侧边菜单的布局,它可以吸引我的应用程序的真实内容。

当我访问链接以访问其他页面时,我希望只重新加载我的应用程序的内容,而不是整个内容。有两个原因,一个是使应用看起来很慢的视觉延迟,两个原因,我可以更容易地显示当前选择的菜单。

enter image description here

angular reload
1个回答
4
投票

你必须为此使用路由。

基本上,您的app.component.html将包含这些行

<app-header></app-header>           // This will render the header component
<router-outlet></router-outlet>     // This will render all the route changes
<app-footer></app-footer>           // This will render the footer

工作示例:页眉和页脚不重新加载,甚至突出显示所选的选项卡

My Portfolio Angular Scaffolding //看看这个,你甚至可以看看它是如何工作的代码。把它放在你想要的一切。

参考

角度路由是一个相当大的主题,值得整个页面。

看看它是如何工作的:Angular.io文档

© www.soinside.com 2019 - 2024. All rights reserved.