-
Notifications
You must be signed in to change notification settings - Fork 27.6k
New router #12926
Comments
+1 |
@georgiosd Since the new router isn't published yet, you're gonna have to build it from source using the http://github.com/angular/angular repo. From there you can take the built file (angular_1_router.js) and use it |
Here is a plunkr with the latest build as of today. |
That's wonderful, thank you. Is there an ETA on a release currently? |
I have no idea. I thought the new router was supposed to come with 1.5, but we'll have to wait and see. |
Indeed! Thanks, closing this now! |
@brandonroberts what sequence of commands do you use to build the router? I did the "normal" |
@georgiosd you need to run |
@brandonroberts can you give us all the sequence of commands to build the router ? I'm a newbie on gulp and it doesn't work with me. |
@vguede Sure. You need to have at least node 5 and at least npm 3.x installed. Install gulp globally The Hope this helps |
@brandonroberts It works fine ! Many thanks ! |
@brandonroberts Thanks for the info. I couldn't use child routes correctly, and can't find any example with child routes. I expanded the plunker you sent with a child route, as I understand it should be used. The Home component has a new outlet, and configures a new route at "/", but this fails with I don't think it should conflict, since the home controller is configuring a child route, it look's like the home controller is receiving the top router instead of a child one. Can someone help me understand how to set up child routes, or point me to a working sample? |
@pauloya Setting up child routes in Angular 1 is a little different then setting them up in Angular 2. To setup up your child routes, you have to place a $routeConfig property on your directive factory function in the parent directive. I forked your plunk and updated it with a working example. http://plnkr.co/edit/2ZNQzWfspvpmMCLRBOdN?p=preview If you also want to look at another example, Its using the upcoming component helper, but the concepts are the same. https://github.com/brandonroberts/angularjs-component-router If you want a newer build you can install the router from npm now.
|
Many thanks @brandonroberts for npm ! |
That's exactly what I needed, thanks! |
@brandonroberts You have the same bug templateUrl <=> $onActivate (issue : angular/angular#4633) on angularjs-component-router. |
@vguede I have no idea when it will be fixed. I normally have a build step that imports the html as is and use the template property. |
Thanks @brandonroberts, I got things working using module.component() ! http://plnkr.co/edit/xdEYFmUCv0xzvEbXrh0p?p=preview $router._childRouter.navigate([...]) Thanks! |
@pauloya I thought whenever you inject the router it will use that component as the parent component for navigating and creating links. In the case of your example, you need to change $router.navigate(['./Son']); to $router.navigate[('/Home', 'Son']); If you want to use parameters with a route, just add the params after each component in the array $router.navigate(['/Home', {name:'HomeParam'}, 'Son', {name:'SonParam'}]); |
Thanks @brandonroberts. |
@pauloya I thought so also. It may be a bug, but I'm not sure. |
It's a nice discussion and helps to find some answers for router |
@pauloya the router delegates navigation to the root router, which explains why you have to provide the full route path even in a child component when navigating programmatically. |
Hi, I'm trying to use the new router, ngComponentRouter in a new project using AngularJs 1.5 and ES6. So i downloaded it with npm (npm install @angular/router) and imported it in my app.js.
console.log(ngComponentRouter) is returning an empty object {}. Therefore i can't instantiate ngComponentRouter.
This will return :
Any ideas what could be done to be able to use it? |
@btribouillet You don't need to import it that way. Just import it and use the string import 'npm/@angular/router/angular1/angular_1_router.js';
angular.module('app', [
'ngComponentRouter'
]
); |
@brandonroberts Thank you! perfectly working ;). |
I talked to fast ;). Actually i'd like to inject it in the configuration of my module.
The commented code is the code i'd like to use (using ngComponentRouter) but returning Unknown provider: $router. This code is working with ui-router. Am i wrong to inject $router instead of something else? |
@nicl there currently isn't a public way to access the params in the constructor. What you would need to do is use the There is an example in Pete's repo here: https://github.com/petebacondarwin/ng1-component-router-demo/blob/master/app/heroes.js#L80-L95 If you look at the |
@nicl also it doesn't strictly make that much sense to access the params in the constructor since the component could be reused. That is why we have the various hooks: |
@brandonroberts @petebacondarwin the |
@andreiho There is a PR for it here: angular/angular#6978, it just hasn't been merged in yet. |
@brandonroberts Oh right, I saw that at some point, just couldn't recall. |
Hopefully @matsko will merge that today. |
@brandonroberts @petebacondarwin thanks for the help and example project! |
@nicl just for the record, until the fix for |
@andreiho that only gives you the root router though. I'd stick to getting the params through the routerOnActivate hook |
It appears the PR was finally merged in, so I went ahead and built the router to fix the issue with lifecycle hooks not working with Gist: https://gist.github.com/andreiho/abc94a492c5986678385
|
@petebacondarwin @brandonroberts is there currently a way to access the params inside the |
Since canActivate is invoked by the injector, the instructions are passed as "locals", which can also be injected...
See https://github.com/petebacondarwin/ng1-component-router-demo/blob/master/app/crisis-center.js#L28 (By the way, I think we ought to rename that hook to be |
@petebacondarwin Thanks, didn't think of that. (And I agree it would be a good idea to rename the hook. That's actually what I tried initially and couldn't figure out why it wasn't working, so I had to go in the source file and find how it was named) |
Is
EDIT My mistake, I guess you can't put |
Yes the |
Is |
@diegohaz yes, its working. The |
But it has not yet been released in version 0.2.0 of the router |
@brandonroberts @petebacondarwin I see. Thank you. By the way, where can I post issues about the ngComponentRouter for Angular 1.x? I want to know if it has support for states/sibling views. |
@diegohaz you should file those here: https://github.com/angular/angular |
Actually for Angular 1.x you can start posting in https://github.com/angular/router |
so with the recent changed to angular2's gulp file, |
@geroyche there is currently no recommended way as the router that we did have is no longer compatible with the latest router for Angular 2, and the old router has outstanding bugs that will not be resolved. |
that's a bit disappointing to hear, since it was communicated as a best-practice approach to use the component router in angular1.5 projects in order to ease a future migration to angular2 (we already switched from "angular-new-router" to the "angular1_router" backport). |
I am sorry and I understand your disappointment. We are working hard to get this fixed for you but we have limited resources and are being pulled in lots of directions. If there are people in the community who want to get involved in working out how to port the router (and the http library) then I would love to get in touch with them. |
Also worth noting that ui-router supports both ng1 and ng2, as well as hybrid ng1/ng2 apps |
true. we specifically chose not to add another dependency, ui-router, based on the notion that the new angular router(s by now) would fix the shortcomings that led to ui-router's existence in the first place. but yes, maybe we should reconsider. |
npm install "@angular/router": "^0.2.0" -D |
I've tried my luck at the Gitter channels with limited success so I'm trying my last resort :)
What's the current way of importing the new component router to a project?
I see most recent work is in angular/angular repo but don't seem to find a recent package anywhere.
The JSPM
angular-new-router
package points to @btford's repo and brings version 0.5.3 which looks pretty outdated.The text was updated successfully, but these errors were encountered: