File tree Expand file tree Collapse file tree 3 files changed +34
-5
lines changed
Expand file tree Collapse file tree 3 files changed +34
-5
lines changed Original file line number Diff line number Diff line change @@ -152,9 +152,27 @@ export class Router {
152152 return this . renavigate ( ) ;
153153 }
154154
155+ /**
156+ * Navigate based on the provided Route Link DSL. It's preferred to navigate with this method
157+ * over `navigateByUrl`.
158+ *
159+ * # Usage
160+ *
161+ * This method takes an array representing the Route Link DSL:
162+ * ```
163+ * ['./MyCmp', {param: 3}]
164+ * ```
165+ * See the {@link RouterLink} directive for more.
166+ */
167+ navigate ( linkParams : any [ ] ) : Promise < any > {
168+ var instruction = this . generate ( linkParams ) ;
169+ return this . navigateByInstruction ( instruction , false ) ;
170+ }
171+
155172
156173 /**
157174 * Navigate to a URL. Returns a promise that resolves when navigation is complete.
175+ * It's preferred to navigate with `navigate` instead of this method, since URLs are more brittle.
158176 *
159177 * If the given URL begins with a `/`, router will navigate absolutely.
160178 * If the given URL does not begin with `/`, the router will navigate relative to this component.
Original file line number Diff line number Diff line change @@ -139,11 +139,7 @@ export function main() {
139139 as : 'child-with-grandchild'
140140 } )
141141 ] ) )
142- . then ( ( _ ) => {
143- // TODO: refactor when https://github.com/angular/angular/pull/4074 lands
144- var instruction = router . generate ( [ '/child-with-grandchild' ] ) ;
145- return router . navigateInstruction ( instruction ) ;
146- } )
142+ . then ( ( _ ) => router . navigate ( [ '/child-with-grandchild' ] ) )
147143 . then ( ( _ ) => {
148144 rootTC . detectChanges ( ) ;
149145 expect ( DOM . getAttribute (
Original file line number Diff line number Diff line change @@ -76,6 +76,21 @@ export function main() {
7676 } ) ;
7777 } ) ) ;
7878
79+ it ( 'should activate viewports and update URL when navigating via DSL' ,
80+ inject ( [ AsyncTestCompleter ] , ( async ) => {
81+ var outlet = makeDummyOutlet ( ) ;
82+
83+ router . registerPrimaryOutlet ( outlet )
84+ . then ( ( _ ) =>
85+ router . config ( [ new Route ( { path : '/a' , component : DummyComponent , as : 'A' } ) ] ) )
86+ . then ( ( _ ) => router . navigate ( [ '/A' ] ) )
87+ . then ( ( _ ) => {
88+ expect ( outlet . spy ( 'activate' ) ) . toHaveBeenCalled ( ) ;
89+ expect ( location . urlChanges ) . toEqual ( [ '/a' ] ) ;
90+ async . done ( ) ;
91+ } ) ;
92+ } ) ) ;
93+
7994 it ( 'should not push a history change on when navigate is called with skipUrlChange' ,
8095 inject ( [ AsyncTestCompleter ] , ( async ) => {
8196 var outlet = makeDummyOutlet ( ) ;
You can’t perform that action at this time.
0 commit comments