當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript common.HashLocationStrategy類代碼示例

本文整理匯總了TypeScript中angular2/platform/common.HashLocationStrategy的典型用法代碼示例。如果您正苦於以下問題:TypeScript HashLocationStrategy類的具體用法?TypeScript HashLocationStrategy怎麽用?TypeScript HashLocationStrategy使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了HashLocationStrategy類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: describe

  describe('HashLocationStrategy', () => {
    var platformLocation: SpyPlatformLocation;
    var locationStrategy: HashLocationStrategy;

    beforeEachProviders(
        () => [HashLocationStrategy, provide(PlatformLocation, {useClass: SpyPlatformLocation})]);

    describe('without APP_BASE_HREF', () => {
      beforeEach(inject([PlatformLocation, HashLocationStrategy], (pl, ls) => {
        platformLocation = pl;
        locationStrategy = ls;
        platformLocation.spy('pushState');
        platformLocation.pathname = '';
      }));

      it('should prepend urls with a hash for non-empty URLs', () => {
        expect(locationStrategy.prepareExternalUrl('foo')).toEqual('#foo');

        locationStrategy.pushState(null, 'Title', 'foo', '');
        expect(platformLocation.spy('pushState')).toHaveBeenCalledWith(null, 'Title', '#foo');
      });

      it('should prepend urls with a hash for URLs with query params', () => {
        expect(locationStrategy.prepareExternalUrl('foo?bar')).toEqual('#foo?bar');

        locationStrategy.pushState(null, 'Title', 'foo', 'bar=baz');
        expect(platformLocation.spy('pushState'))
            .toHaveBeenCalledWith(null, 'Title', '#foo?bar=baz');
      });

      it('should prepend urls with a hash for URLs with just query params', () => {
        expect(locationStrategy.prepareExternalUrl('?bar')).toEqual('#?bar');

        locationStrategy.pushState(null, 'Title', '', 'bar=baz');
        expect(platformLocation.spy('pushState')).toHaveBeenCalledWith(null, 'Title', '#?bar=baz');
      });

      it('should not prepend a hash to external urls for an empty internal URL', () => {
        expect(locationStrategy.prepareExternalUrl('')).toEqual('');

        locationStrategy.pushState(null, 'Title', '', '');
        expect(platformLocation.spy('pushState')).toHaveBeenCalledWith(null, 'Title', '');
      });
    });

    describe('with APP_BASE_HREF with neither leading nor trailing slash', () => {
      beforeEachProviders(() => [provide(APP_BASE_HREF, {useValue: 'app'})]);

      beforeEach(inject([PlatformLocation, HashLocationStrategy], (pl, ls) => {
        platformLocation = pl;
        locationStrategy = ls;
        platformLocation.spy('pushState');
        platformLocation.pathname = '';
      }));

      it('should prepend urls with a hash for non-empty URLs', () => {
        expect(locationStrategy.prepareExternalUrl('foo')).toEqual('#app/foo');

        locationStrategy.pushState(null, 'Title', 'foo', '');
        expect(platformLocation.spy('pushState')).toHaveBeenCalledWith(null, 'Title', '#app/foo');
      });

      it('should prepend urls with a hash for URLs with query params', () => {
        expect(locationStrategy.prepareExternalUrl('foo?bar')).toEqual('#app/foo?bar');

        locationStrategy.pushState(null, 'Title', 'foo', 'bar=baz');
        expect(platformLocation.spy('pushState'))
            .toHaveBeenCalledWith(null, 'Title', '#app/foo?bar=baz');
      });

      it('should not prepend a hash to external urls for an empty internal URL', () => {
        expect(locationStrategy.prepareExternalUrl('')).toEqual('#app');

        locationStrategy.pushState(null, 'Title', '', '');
        expect(platformLocation.spy('pushState')).toHaveBeenCalledWith(null, 'Title', '#app');
      });
    });

    describe('with APP_BASE_HREF with leading slash', () => {
      beforeEachProviders(() => [provide(APP_BASE_HREF, {useValue: '/app'})]);

      beforeEach(inject([PlatformLocation, HashLocationStrategy], (pl, ls) => {
        platformLocation = pl;
        locationStrategy = ls;
        platformLocation.spy('pushState');
        platformLocation.pathname = '';
      }));

      it('should prepend urls with a hash for non-empty URLs', () => {
        expect(locationStrategy.prepareExternalUrl('foo')).toEqual('#/app/foo');

        locationStrategy.pushState(null, 'Title', 'foo', '');
        expect(platformLocation.spy('pushState')).toHaveBeenCalledWith(null, 'Title', '#/app/foo');
      });

      it('should prepend urls with a hash for URLs with query params', () => {
        expect(locationStrategy.prepareExternalUrl('foo?bar')).toEqual('#/app/foo?bar');

        locationStrategy.pushState(null, 'Title', 'foo', 'bar=baz');
        expect(platformLocation.spy('pushState'))
//.........這裏部分代碼省略.........
開發者ID:844496869,項目名稱:angular,代碼行數:101,代碼來源:hash_location_strategy_spec.ts

示例2: it

      it('should prepend urls with a hash for URLs with query params', () => {
        expect(locationStrategy.prepareExternalUrl('foo?bar')).toEqual('#app/foo?bar');

        locationStrategy.pushState(null, 'Title', 'foo', 'bar=baz');
        expect(platformLocation.spy('pushState'))
            .toHaveBeenCalledWith(null, 'Title', '#app/foo?bar=baz');
      });
開發者ID:844496869,項目名稱:angular,代碼行數:7,代碼來源:hash_location_strategy_spec.ts


注:本文中的angular2/platform/common.HashLocationStrategy類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。