當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。