Skip to content

Commit

Permalink
feat(router): add regex matchers
Browse files Browse the repository at this point in the history
@petebacondarwin deserves credit for most of this commit.

This allows you to specify a regex and serializer function instead
of the path DSL in your route declaration.

```
@RouteConfig([
  { regex: '[a-z]+.[0-9]+',
    serializer: (params) => `{params.a}.params.b}`,
    component: MyComponent }
])
class Component {}
```

Closes #7325
Closes #7126
  • Loading branch information
btford authored and vikerman committed Mar 3, 2016
1 parent 2548ce8 commit 75343eb
Show file tree
Hide file tree
Showing 74 changed files with 986 additions and 738 deletions.
21 changes: 12 additions & 9 deletions modules/angular1_router/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@ var fs = require('fs');
var ts = require('typescript');

var files = [
'lifecycle_annotations_impl.ts',
'utils.ts',
'url_parser.ts',
'route_recognizer.ts',
'route_config_impl.ts',
'async_route_handler.ts',
'sync_route_handler.ts',
'component_recognizer.ts',
'lifecycle/lifecycle_annotations_impl.ts',
'lifecycle/route_lifecycle_reflector.ts',
'route_config/route_config_impl.ts',
'route_config/route_config_normalizer.ts',
'rules/route_handlers/async_route_handler.ts',
'rules/route_handlers/sync_route_handler.ts',
'rules/rules.ts',
'rules/rule_set.ts',
'rules/route_paths/route_path.ts',
'rules/route_paths/param_route_path.ts',
'rules/route_paths/regex_route_path.ts',
'instruction.ts',
'path_recognizer.ts',
'route_config_nomalizer.ts',
'route_lifecycle_reflector.ts',
'route_registry.ts',
'router.ts'
];
Expand Down
1 change: 0 additions & 1 deletion modules/angular1_router/src/ng_outlet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ function ngOutletFillContentDirective($compile) {




function routerTriggerDirective($q) {
return {
require: '^ngOutlet',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ describe('Navigation lifecycle', function () {

expect(spy).toHaveBeenCalled();
var args = spy.calls.mostRecent().args;
expect(args[0].params).toEqual({name: 'brian'});
expect(args[0].params).toEqual(jasmine.objectContaining({name: 'brian'}));
expect(args[1]).toBe($http);
}));

Expand Down
2 changes: 1 addition & 1 deletion modules/angular2/platform/testing/browser_static.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {MockAnimationBuilder} from 'angular2/src/mock/animation_builder_mock';
import {MockDirectiveResolver} from 'angular2/src/mock/directive_resolver_mock';
import {MockViewResolver} from 'angular2/src/mock/view_resolver_mock';
import {MockLocationStrategy} from 'angular2/src/mock/mock_location_strategy';
import {LocationStrategy} from 'angular2/src/router/location_strategy';
import {LocationStrategy} from 'angular2/src/router/location/location_strategy';
import {MockNgZone} from 'angular2/src/mock/ng_zone_mock';

import {XHRImpl} from "angular2/src/platform/browser/xhr_impl";
Expand Down
2 changes: 1 addition & 1 deletion modules/angular2/platform/testing/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {MockAnimationBuilder} from 'angular2/src/mock/animation_builder_mock';
import {MockDirectiveResolver} from 'angular2/src/mock/directive_resolver_mock';
import {MockViewResolver} from 'angular2/src/mock/view_resolver_mock';
import {MockLocationStrategy} from 'angular2/src/mock/mock_location_strategy';
import {LocationStrategy} from 'angular2/src/router/location_strategy';
import {LocationStrategy} from 'angular2/src/router/location/location_strategy';
import {MockNgZone} from 'angular2/src/mock/ng_zone_mock';

import {TestComponentBuilder} from 'angular2/src/testing/test_component_builder';
Expand Down
22 changes: 11 additions & 11 deletions modules/angular2/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@
*/

export {Router} from './src/router/router';
export {RouterOutlet} from './src/router/router_outlet';
export {RouterLink} from './src/router/router_link';
export {RouterOutlet} from './src/router/directives/router_outlet';
export {RouterLink} from './src/router/directives/router_link';
export {RouteParams, RouteData} from './src/router/instruction';
export {PlatformLocation} from './src/router/platform_location';
export {PlatformLocation} from './src/router/location/platform_location';
export {RouteRegistry, ROUTER_PRIMARY_COMPONENT} from './src/router/route_registry';
export {LocationStrategy, APP_BASE_HREF} from './src/router/location_strategy';
export {HashLocationStrategy} from './src/router/hash_location_strategy';
export {PathLocationStrategy} from './src/router/path_location_strategy';
export {Location} from './src/router/location';
export * from './src/router/route_config_decorator';
export {LocationStrategy, APP_BASE_HREF} from './src/router/location/location_strategy';
export {HashLocationStrategy} from './src/router/location/hash_location_strategy';
export {PathLocationStrategy} from './src/router/location/path_location_strategy';
export {Location} from './src/router/location/location';
export * from './src/router/route_config/route_config_decorator';
export * from './src/router/route_definition';
export {OnActivate, OnDeactivate, OnReuse, CanDeactivate, CanReuse} from './src/router/interfaces';
export {CanActivate} from './src/router/lifecycle_annotations';
export {CanActivate} from './src/router/lifecycle/lifecycle_annotations';
export {Instruction, ComponentInstruction} from './src/router/instruction';
export {OpaqueToken} from 'angular2/core';
export {ROUTER_PROVIDERS_COMMON} from 'angular2/src/router/router_providers_common';
export {ROUTER_PROVIDERS, ROUTER_BINDINGS} from 'angular2/src/router/router_providers';

import {RouterOutlet} from './src/router/router_outlet';
import {RouterLink} from './src/router/router_link';
import {RouterOutlet} from './src/router/directives/router_outlet';
import {RouterLink} from './src/router/directives/router_link';
import {CONST_EXPR} from './src/facade/lang';

/**
Expand Down
4 changes: 2 additions & 2 deletions modules/angular2/router/router_link_dsl.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {TEMPLATE_TRANSFORMS} from 'angular2/compiler';
import {Provider} from 'angular2/core';
import {RouterLinkTransform} from 'angular2/src/router/router_link_transform';
import {RouterLinkTransform} from 'angular2/src/router/directives/router_link_transform';
import {CONST_EXPR} from 'angular2/src/facade/lang';

export {RouterLinkTransform} from 'angular2/src/router/router_link_transform';
export {RouterLinkTransform} from 'angular2/src/router/directives/router_link_transform';

/**
* Enables the router link DSL.
Expand Down
2 changes: 1 addition & 1 deletion modules/angular2/src/mock/location_mock.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Injectable} from 'angular2/src/core/di';
import {EventEmitter, ObservableWrapper} from 'angular2/src/facade/async';
import {ListWrapper} from 'angular2/src/facade/collection';
import {Location} from 'angular2/src/router/location';
import {Location} from 'angular2/src/router/location/location';

/**
* A spy for {@link Location} that allows tests to fire simulated location events.
Expand Down
2 changes: 1 addition & 1 deletion modules/angular2/src/mock/mock_location_strategy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Injectable} from 'angular2/src/core/di';
import {EventEmitter, ObservableWrapper} from 'angular2/src/facade/async';
import {LocationStrategy} from 'angular2/src/router/location_strategy';
import {LocationStrategy} from 'angular2/src/router/location/location_strategy';


/**
Expand Down
2 changes: 1 addition & 1 deletion modules/angular2/src/platform/worker_render_common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import {BrowserDomAdapter} from './browser/browser_adapter';
import {wtfInit} from 'angular2/src/core/profile/wtf_init';
import {MessageBasedRenderer} from 'angular2/src/web_workers/ui/renderer';
import {MessageBasedXHRImpl} from 'angular2/src/web_workers/ui/xhr_impl';
import {BrowserPlatformLocation} from 'angular2/src/router/browser_platform_location';
import {BrowserPlatformLocation} from 'angular2/src/router/location/browser_platform_location';
import {
ServiceMessageBrokerFactory,
ServiceMessageBrokerFactory_
Expand Down
163 changes: 0 additions & 163 deletions modules/angular2/src/router/component_recognizer.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {Directive} from 'angular2/core';
import {isString} from 'angular2/src/facade/lang';

import {Router} from './router';
import {Location} from './location';
import {Instruction} from './instruction';
import {Router} from '../router';
import {Location} from '../location/location';
import {Instruction} from '../instruction';

/**
* The RouterLink directive lets you link to specific parts of your app.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import {
Dependency
} from 'angular2/core';

import * as routerMod from './router';
import {ComponentInstruction, RouteParams, RouteData} from './instruction';
import * as hookMod from './lifecycle_annotations';
import {hasLifecycleHook} from './route_lifecycle_reflector';
import {OnActivate, CanReuse, OnReuse, OnDeactivate, CanDeactivate} from './interfaces';
import * as routerMod from '../router';
import {ComponentInstruction, RouteParams, RouteData} from '../instruction';
import * as hookMod from '../lifecycle/lifecycle_annotations';
import {hasLifecycleHook} from '../lifecycle/route_lifecycle_reflector';
import {OnActivate, CanReuse, OnReuse, OnDeactivate, CanDeactivate} from '../interfaces';

let _resolveToTrue = PromiseWrapper.resolve(true);

Expand Down
12 changes: 5 additions & 7 deletions modules/angular2/src/router/instruction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,15 +224,11 @@ export class ResolvedInstruction extends Instruction {
/**
* Represents a resolved default route
*/
export class DefaultInstruction extends Instruction {
export class DefaultInstruction extends ResolvedInstruction {
constructor(component: ComponentInstruction, child: DefaultInstruction) {
super(component, child, {});
}

resolveComponent(): Promise<ComponentInstruction> {
return PromiseWrapper.resolve(this.component);
}

toLinkUrl(): string { return ''; }

/** @internal */
Expand Down Expand Up @@ -292,8 +288,7 @@ export class RedirectInstruction extends ResolvedInstruction {


/**
* A `ComponentInstruction` represents the route state for a single component. An `Instruction` is
* composed of a tree of these `ComponentInstruction`s.
* A `ComponentInstruction` represents the route state for a single component.
*
* `ComponentInstructions` is a public API. Instances of `ComponentInstruction` are passed
* to route lifecycle hooks, like {@link CanActivate}.
Expand All @@ -308,6 +303,9 @@ export class ComponentInstruction {
reuse: boolean = false;
public routeData: RouteData;

/**
* @internal
*/
constructor(public urlPath: string, public urlParams: string[], data: RouteData,
public componentType, public terminal: boolean, public specificity: string,
public params: {[key: string]: any} = null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import {makeDecorator} from 'angular2/src/core/util/decorators';
import {CanActivate as CanActivateAnnotation} from './lifecycle_annotations_impl';
import {ComponentInstruction} from './instruction';
import {ComponentInstruction} from '../instruction';

export {
routerCanReuse,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
library angular.router.route_lifecycle_reflector;

import 'package:angular2/src/router/lifecycle_annotations_impl.dart';
import 'package:angular2/src/router/lifecycle/lifecycle_annotations_impl.dart';
import 'package:angular2/src/router/interfaces.dart';
import 'package:angular2/src/core/reflection/reflection.dart';

Expand Down
File renamed without changes.
Loading

0 comments on commit 75343eb

Please sign in to comment.