angular-fullstack / generator-angular-fullstack

Yeoman generator for an Angular app with an Express server
https://awk34.gitbook.io/generator-angular-fullstack
6.12k stars 1.24k forks source link

Change anchor hrefs to ui-sref when using ui-router #331

Closed jpstone closed 9 years ago

jpstone commented 10 years ago

When spinning up a new app w/ ui-router, I find myself having to find and change each href to ui-sref. Would be preferable to have this automatically set when using the ui-router option.

remicastaing commented 10 years ago

Is it all href or just the ng-href?

All ng-href are in the navbar files.

jpstone commented 10 years ago

The navbar uses href, not ng-href. I find myself changing this to ui-sref in order to properly navigate to the desired $state.

Also, when logging in, login.controller calls '$location.path('/')'. I think if using ui-router, this should be something like $state.go('main') instead.

remicastaing commented 10 years ago

I don't understand. I went through the generator and just found this:

Searching 150 files for "ng-href" (regex, case sensitive)

/Users/remi/Workspaces/JS/generator-angular-fullstack/app/templates/client/components/navbar/navbar(html).html:
   13        <ul class="nav navbar-nav">
   14          <li ng-repeat="item in menu" ng-class="{active: isActive(item.link)}">
   15:             <a ng-href="{{item.link}}">{{item.title}}</a>
   16          </li><% if(filters.auth) { %>
   17          <li ng-show="isAdmin()" ng-class="{active: isActive('/admin')}"><a href="/admin">Admin</a></li><% } %>

/Users/remi/Workspaces/JS/generator-angular-fullstack/app/templates/client/components/navbar/navbar(jade).jade:
   12        ul.nav.navbar-nav
   13          li(ng-repeat='item in menu', ng-class='{active: isActive(item.link)}')
   14:           a(ng-href='{{item.link}}') {{item.title}}<% if(filters.auth) { %>
   15  
   16          li(ng-show='isAdmin()', ng-class='{active: isActive("/admin")}')

2 matches across 2 files
jpstone commented 10 years ago

Ok, so ng-href is only for $scope.menu in navbar.controllers. The rest of the menu li's use href.

I think they both should be ui-sref if using ui-router. For example, I changed ng-href to ui-sref="main" for "Home", and obviously all the other hrefs as well (to their proper states).

remicastaing commented 10 years ago

To avoid such code in several place all over the files:

<% if(filters.ngroute) { %>
href='/'
<% } %><% if(filters.uirouter) { %>
ui-sref='main'
<% } %>

they may be better to write separate files for ui-router:

and also the four associated jade file.

In following files:

$location.path('/'); may be replaced by $state.go('main'). Same thing for the cofffescript files.