【发布时间】:2021-02-08 05:48:53
【问题描述】:
app.component.html
<!--I wish to keep this structure like this, because menu.component has position sticky at top: 0-->
<app-home></app-home>
<app-menu></app-menu>
<app-about></app-about>
<app-projects></app-projects>
<app-contact></app-contact>
<app-footer></app-footer>
menu.component.html
<!--On anchor link click, navigate to corresponding component-->
<nav>
<a>Home</a>
<a>About</a>
<a>Projects</a>
<a>Contact</a>
</nav>
home.component.html、about.component.html、projects.component.html、contact.component.html
<!--Basic structure-->
<section>
<p>component works!</p>
</section>
网站基本结构的链接 https://stackblitz.com/edit/angular-ivy-ufce4g
我会分享一个指向实际网站(我的个人网站)的链接,但我不知道我是否被允许。
【问题讨论】:
-
你看过 Angular 路由器吗?我相信这就是你想要的。见angular.io/guide/router
-
我希望在不使用
的情况下渲染 app.component.html 中的所有组件。因为否则路由器只会渲染一个组件。并从我的 menu.component.html 锚点上单击以将相应的组件滚动到窗口顶部,就像本机锚点 href 行为一样。
标签: html angular typescript sass anchor