Angularjs   发布时间:2022-04-20  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了拆分 – 从主应用程序文件中分离角度2路径配置大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我想将路由配置从app文件分成不同的文件,如(routeConfig.ts).有可能的?

例如:

import {Component} from 'angular2/core';
import {RouteConfig,ROUTER_DIRECTIVES} from 'angular2/router';
import {DashboardComponent} from './dashboard/dashboard.component';


import {messagesComponent} from '../modules/messages/messages.component';


@Component({
    SELEctor: 'app',directives: [
      ROUTER_DIRECTIVES
    ],templateUrl: './built/application/app.html'
})

@RouteConfig([
  {
    path: '/',name: 'Dashboard',component: DashboardComponent,useAsDefault: true
  }
])

export class AppComponent {}

我想将@RouteConfig params移动到不同的文件中,然后将其加载到主app文件中.有可能的?谢谢. (路由配置会很大,所以我想分开这个).

一个麻烦,就是当我尝试将配置移动到不同的文件并尝试在应用程序文件中导入JSON时 – 我得到了未定义组件的错误.因为componentsName不是一个字符串.无法解决这个问题.

您当然可以将所有路径定义移动到单独的文件中.

在route-deFinitions.ts这样的文件中:

import { RouteDeFinition } from 'angular2/router';
import { HomeComponent } from './home/home.component';
import { AboutComponent } from './about/about.component';
import { InfoComponent } from './info/info.component';

export const RouteDeFinitions: RouteDeFinition[] = [
    {
        path: '/',name: 'Home',component: HomeComponent,useAsDefault: true
    },{
        path: '/about',name: 'About',component: AboutComponent
    },{
        path: '/info',name: 'Info',component: InfoComponent
    }
];

然后回到你的app.component.ts文件中:

import { Component } from 'angular2/core';
import { RouteConfig,ROUTER_DIRECTIVES,ROUTER_PROVIDERS } from 'angular2/router';
import { RouteDeFinitions } from './route-deFinitions';

@Component({
    SELEctor: 'my-app',templateUrl: 'app/app.component.html',directives: [ROUTER_DIRECTIVES],providers: [
      ROUTER_PROVIDERS
    ]
})
@RouteConfig(RouteDeFinitions)
export class AppComponent { }

大佬总结

以上是大佬教程为你收集整理的拆分 – 从主应用程序文件中分离角度2路径配置全部内容,希望文章能够帮你解决拆分 – 从主应用程序文件中分离角度2路径配置所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。