1

我尝试在 index.page 上将 angularjs 与 fullpage.js 结合起来。此外,仍然有一些页面只是通过路由正常呈现。

这是我在 app.js 中的路线

app.config(['$routeProvider', '$httpProvider', '$locationProvider', function($routeProvider, $httpProvider, $locationProvider) {
  $locationProvider.html5Mode(true);
  $routeProvider
    // Below are all sections at index page
    .when('/#index', {
      controller: 'WelcomeCtrl',
      templateUrl: 'views/welcome/index.html'
    })
    .when('/#products', {
    })
    .when('/#learn', {
    })
    .when('/#help', {
    })
    .when('/#contact', {
    })

    // Other pages not using fullpage.js
    .when('/cases', {
      controller: 'CasesCtrl',
      templateUrl: 'views/welcome/cases/index.html'
    })
    .when('/users', {
      controller: 'UsersCtrl',
      templateUrl: 'views/users/login.html'
    })
    .otherwise({
      redirectTo: '/'
    });
});

但是,当我滚动索引处的部分时,每个都调用我的第一个路由规则,然后呈现索引页面,尽管该部分已正确滚动到。

此外,将 html5Mode 设置为 true 时,带有哈希标记的路由规则似乎不起作用,我的 urls 变成了http://xxx/%23products,如何解决这个问题?

谢谢。

4

1 回答 1

1

好的,我通过一些黑客解决了它。

首先,我在 fullpage.js 中将标志“ lockAnchors ”设置为“true”。

其次,我为 navbar 指令设置了一个控制器,它提供了一个$scope.scrollTo(anchor),然后在单击并调用 scrollTo(anchor) 后,我使用ngSilent静默更改 url。

最后,我检查在哪个页面单击导航栏。如果不是带有 fullpage.js 的索引页面,我使用$location.path("/")回到索引,然后默默地将锚点添加到 url,使用 fullpage.js 方法滚动到锚点(经过超时约 1200~1500)。

于 2016-01-11T17:18:10.960 回答