Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
912 views
in Technique[技术] by (71.8m points)

angularjs - Foundation for Apps : How to replace the default Dynamic Routing plugin?

Zurb's Foundation For Apps is using a special plugin that creates routes directly from each view, it will parse all the HTML files to find this kind of markdown structure :

---
name: items
url: /items
controller: ItemCtrl
---

which will use to generate the necessary angular Dynamic Routing code and use gulp to compile a routes.js file which will contain this :

var foundationRoutes = [
    {
        "name":"items",
        "url":"/items",
        "controller":"ItemCtrl",
        "path":"templates/items.html"
    }
];

So my question is, if I want to change my templates path or restructre my app or if I need more advanced use for angular's ui-router specially state.resolve and state.views, Is there a way to replace the built-in Dynamic Routing plugin by a $stateProvider instance without breaking any of the other F4A's built-in components ?


UPDATE : The special plugin is called Front Router and this is its Github Repository.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This solution solved my issue :

by @escapedcat from this github issue page :

gulpfile.js: comment out the FA router part :

// Copies your app's page templates and generates URLs for them
gulp.task('copy-templates', ['copy'], function() {
  return gulp.src('./client/templates/**/*.html')
    // .pipe(router({ 
    //   path: 'build/assets/js/routes.js',
    //   root: 'client'
    // }))
    .pipe(gulp.dest('./build/templates'))
  ;
});

index.html: remove the routes.js

<script src="/assets/js/foundation.js"></script>
<!-- <script src="/assets/js/routes.js"></script> -->
<script src='//maps.googleapis.com/maps/api/js?sensor=false'></script>
<script src="/assets/js/app.js"></script>

app.js: comment out the dynamicRouting modules and modify the config part :

 angular.module('application', [
    ...
    //foundation
    'foundation',
    // 'foundation.dynamicRouting',
    // 'foundation.dynamicRouting.animations',
    ...
    ])
    .config(
      function($stateProvider, $urlRouterProvider) {
        $stateProvider
          .state('yourstate', {
              url: '/yoururl',
              templateUrl: 'templates/yourTemplate.html',
              controller: 'YourController',
              resolve: {
                  // you can use resolve here, yay!
                  // promiseFooData: ['Restangular', function(Restangular) {
                  //     return Restangular.one('foo').get();
                  // }]
              }
          });
    })
  .run(run)
;

You need a .state entry for each route/template you had before. In this example the part before looked like this :

---
name: yourstate
url: /yoururl
controller: YourController
---

NOTE: Animation may also be added to state (after version 1.1 I guess) :

$stateProvider
  .state('home', {
    url: '/',
    templateUrl: 'templates/home.html',
    animation: {
      enter: 'slideInDown',
      leave: 'fadeOut'
    }
  });

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...