Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/reporting-services/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular6 来自数据库的Anuglar 6路由_Angular6 - Fatal编程技术网

Angular6 来自数据库的Anuglar 6路由

Angular6 来自数据库的Anuglar 6路由,angular6,Angular6,Iam使用默认路由配置处理angular 6应用程序, 我的问题是如何在用户登录后从数据库加载路由这就是我现在的路由 const routes: Routes = [ { path: "", redirectTo: "dashboard", pathMatch: "full" }, { path: "services", data: { breadcrumb: "Services" }, component: ServicesComp

Iam使用默认路由配置处理angular 6应用程序, 我的问题是如何在用户登录后从数据库加载路由这就是我现在的路由

const routes: Routes = [
  {
    path: "",
    redirectTo: "dashboard",
    pathMatch: "full"
  },

  {
    path: "services",
    data: { breadcrumb: "Services" },
    component: ServicesComponent,

  }]
api将返回以下结果

{Path: "/Services", Component: "ServicesComponent"}
{Path: "/Dashboard", Component: "DashboardComponent"}
那么我如何用新值覆盖路由呢


提前感谢

无论何时何地,您都可以在
路由器
实例中添加路由

您需要访问routes阵列并添加一个新阵列,如下所示:

this.router.config.unshift({path: 'myNewRoute', component: ProductListComponent});
let mapping = {
  'myNewRoute': ProductListComponent,
   ...
}
装饰器元数据解决方案

在您的情况下,您需要访问
模块
元数据,更准确地说是
装饰器
的声明,以搜索您需要的组件。您可以检查该组件的名称是否与DB接收到的名称匹配

let compName = 'ProductListComponent';
let comp: Type<any> = (<any>AppModule).__annotations__[0].declarations.find(comp => {
  return comp.name === compName;
});

this.router.config.unshift({path: 'myNewRoute', component: comp});
然后按如下方式取消移动新路线:

this.router.config.unshift({path: 'myNewRoute', component: mapping['myNewRoute']});

谢谢,但这里的组件名称是type而不是string,我需要的是生成路由而不是添加项我不明白“generate route”是什么意思。能否在开始时添加所有路由并使用AuthGuard管理auth?或者,您可以添加所有路由,然后添加一些重定向,这样您就可以使用Strings。如果dinamyc路由的组合不是很大,您可以在db和angular之间定义一个接口,例如,基于用户角色,该场景是在用户登录后,我获得与用户相关的所有菜单,然后我想将它们推送到route,因此我在Ngonin上创建了新的组件navcomponent如何访问route并将字符串组件名称转换为组件的对象感谢您的帮助,我在尝试将应用程序模块添加到组件时只有一个问题,检测到循环依赖项中的警告:src\app\app nav\app-nav.component.ts->src\app\app.module.ts->src\app\app nav\app-nav.component.ts