当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript router.DefaultUrlSerializer类代码示例

本文整理汇总了TypeScript中@angular/router.DefaultUrlSerializer的典型用法代码示例。如果您正苦于以下问题:TypeScript DefaultUrlSerializer类的具体用法?TypeScript DefaultUrlSerializer怎么用?TypeScript DefaultUrlSerializer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了DefaultUrlSerializer类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: serialize

  serialize(tree: UrlTree): any {
    let dus = new DefaultUrlSerializer(),
        path = dus.serialize(tree);

    let at = new RegExp(/%40/g);

   // use your regex to replace as per your requirement.
    return path.replace(at, '@');
  }
开发者ID:reTHINK-project,项目名称:dev-smart-contextual-assistance-app,代码行数:9,代码来源:CustomURLSerializer.ts

示例2: createState

function createState(
    url: string,
    outletName: string,
    isPageNav: boolean = false,
    isRoot: boolean = false) {
    const urlSerializer = new DefaultUrlSerializer();
    const stateUrlTree: UrlTree = urlSerializer.parse(url);
    const rootOutlets = stateUrlTree.root.children;

    return {
        segmentGroup: isRoot ? stateUrlTree.root : rootOutlets[outletName],
        isPageNavigation: isPageNav,
        isRootSegmentGroup: isRoot,
    };
}
开发者ID:NathanWalker,项目名称:nativescript-angular,代码行数:15,代码来源:ns-location-strategy.ts

示例3: parse

 parse(url: any): UrlTree {
   let dus = new DefaultUrlSerializer();
   return dus.parse(url);
 }
开发者ID:reTHINK-project,项目名称:dev-smart-contextual-assistance-app,代码行数:4,代码来源:CustomURLSerializer.ts

示例4: describe

describe('CustomUrlSerializer', () => {

  // The url serializer created for this app that correctly encodes parentheses
  let customUrlSerializer: CustomUrlSerializer;

  // The url serializer that comes with Angular 2 and doesn't encode parentheses
  let defaultUrlSerializer: DefaultUrlSerializer;

  beforeEach(() => {
      customUrlSerializer = new CustomUrlSerializer();
      defaultUrlSerializer = new DefaultUrlSerializer();
  });

  describe('parse', () => {

    describe('when a regular url without need for any special encoding/escaping is given', () => {
      it("the serializer's parsing method does not escape anything ", () => {

        let url: string = '/explore-code/agencies/DOJ';

        let expectedUrlSegments: Object[] = [
          {'path': 'explore-code', 'parameters': {}},
          {'path': 'agencies', 'parameters': {}},
          {'path': 'DOJ', 'parameters': {}}
        ];

        let actualUrlSegments = customUrlSerializer.parse(url).root.children.primary.segments;

        // Compare the value of the url segments, not whether they're techncially the same object in memory
        expect(JSON.stringify(actualUrlSegments)).toEqual(JSON.stringify(expectedUrlSegments));

      });
    });

    describe('when a url with escaped parentheses is used', () => {
      it('the serializer parsed and unescaped correctly', () => {

        let url: string = '/explore-code/agencies/DOJ/repos/Better%20View%20Pane%20Args%20%28Drupal%20module%29';

        let expected: Array<Object> = [
          {path: 'explore-code', parameters: {}},
          {path: 'agencies', parameters: {}},
          {path: 'DOJ', parameters: {}},
          {path: 'repos', parameters: {}},
          {path: 'Better View Pane Args (Drupal module)', parameters: {}}
        ];

        let actual = customUrlSerializer.parse(url).root.children.primary.segments;

        expect(JSON.stringify(actual)).toEqual(JSON.stringify(expected));

      });
    });

    describe('when a url with unescaped spaces and parentheses is used', () => {
      it('the serializer parsed correctly', () => {

        let url: string = '/explore-code/agencies/DOJ/repos/Better View Pane Args (Drupal module)';

        let expected: Array<Object> = [
          {path: 'explore-code', parameters: {}},
          {path: 'agencies', parameters: {}},
          {path: 'DOJ', parameters: {}},
          {path: 'repos', parameters: {}},
          {path: 'Better View Pane Args (Drupal module)', parameters: {}}
        ];

        let actual = customUrlSerializer.parse(url).root.children.primary.segments;

        expect(JSON.stringify(actual)).toEqual(JSON.stringify(expected));

      });
    });

  });

  describe('serialize', () => {
    describe('when a normal url tree without parentheses', () => {
      it('returns the correct url', () => {

        let originalUrl: string = '/explore-code/agencies/NASA';

        let urlTree: UrlTree = defaultUrlSerializer.parse(originalUrl);

        let actualUrl: string = customUrlSerializer.serialize(urlTree);

        /* we're basically checking if the customer url serializer
         * gives the same results as the default url serializer
         * when there are no parentheses present
         */
        expect(actualUrl).toEqual(originalUrl);

      });
    });

    describe('when a urlTree represnting a url with parenthese is given', () => {
      it('the Custom Url Serializer should correctly serialize with escaping', () => {

        let originalUrl: string = '/explore-code/agencies/NASA/' +
          'repos/Abaqus%20User%20Subroutine%20Verification%20%28abaverify%29';
//.........这里部分代码省略.........
开发者ID:presidential-innovation-fellows,项目名称:code-gov-web,代码行数:101,代码来源:custom-url-serializer.spec.ts

示例5: it

      it('returns the correct url', () => {

        let originalUrl: string = '/explore-code/agencies/NASA';

        let urlTree: UrlTree = defaultUrlSerializer.parse(originalUrl);

        let actualUrl: string = customUrlSerializer.serialize(urlTree);

        /* we're basically checking if the customer url serializer
         * gives the same results as the default url serializer
         * when there are no parentheses present
         */
        expect(actualUrl).toEqual(originalUrl);

      });
开发者ID:presidential-innovation-fellows,项目名称:code-gov-web,代码行数:15,代码来源:custom-url-serializer.spec.ts


注:本文中的@angular/router.DefaultUrlSerializer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。