如何替换 angular 4 中的旧选择器内容或将其重定向到完整的新页面

how to replace the old selector content in angular 4 or redirect it to full new page

我在 Angular 4 中有一个索引页面,登录后,我想替换旧页面内容或至少将其重定向到仪表板。在索引页上有关于我们的东西,在仪表板上有自定义。

我已经尝试过我认为互联网上的每件事都像:

{ path: '', redirect To: '/dashboard', path Match: 'full' }
defaulter

我认为您无法 "replace" 根选择器。相反,您可以将其更改为 only contain a router outlet:

app.component.html

<router-outlet></router-outlet>

然后您路由到此路由器出口的任何内容都可以使用整个页面并替换任何 menu/navigation 组件。

然后您可以拥有类似 shell 组件的东西,其中包含所需的菜单。

shell.component.html

<mh-menu></mh-menu>

<div class='container'>
    <router-outlet></router-outlet>
</div>

然后您可以将此 shell 组件替换为具有自己菜单的任何其他组件。

我这里有一个例子:https://github.com/DeborahK/MovieHunter-routing

这是一张显示应用程序路由器插座和 shell 组件路由器插座的图片: