0

URL パスにいるので、リンクをhttp://localhost:3000/u#/クリックしてに移動します。サーバーにリクエストを送信せずにこれを行う必要があります。しかし、それはリンクを 2 回クリックしたときにのみ発生します。hrefhttp://localhost:3000/u#/76457898/profilehref

初めてクリックすると、 にリダイレクトされhttp://localhost:3000/u#/76457898ます。2 回目だけクリックすると、ページはリダイレクトされず、users.profile状態だけが取得され<div ui-view><div>ます。

http://localhost:3000/u#/と同じページに移動しhttp://localhost:3000/u#/76457898ます。

HTML

<a href="{{goToUIState('users.profile', user.userId)}}">
    <!--stuff-->
</a>

Angular UI ルーターを使用した AngularJS

.state('users', {
    url: '/:userId',
    abstract: true,
    resolve: {
        user: ['$cookies', '$stateParams', '$http', 'localStorageService',
            function($cookies, $stateParams, $http, localStorageService) {
                var uid = $cookies.uid || localStorageService.get('uid');
                return $http.get('/api/users/' + uid).success(function (resp) {
                    localStorageService.set('uid', uid);
                    return resp;
                })
            }
        ]
    },
    views: {
        'home': {
            templateUrl: '/partials/user/index.html',
            controller: ['$scope','$state', 'user', '$stateParams', function($scope, $state, user, $stateParams) {
                $scope.user = user.data;

                //dynamic ui-sref do not work, so creating a function to do that with $state.href()
                $scope.goToUIState = function(state, userId) {
                    return $state.href(state, {userId: userId});
                }
                $state.go('users.home');
            }]
        }
    }
})

.state('users.home', {
    url: '',
    templateUrl: '/partials/user/users.home.html',
    controller: [$scope', 'user', function($scope, user) {
        $scope.user = user.data;
    }]

})

.state('users.profile', {
    url: '/profile',
    templateUrl: '/partials/user/users.profile.html',
    controller: ['$scope', '$rootScope', 'user', '$http', 'fileUpload',
        function($scope, $rootScope, user, $http, fileUpload) {
            $scope.user = user.data;
            //stuff
        }]
})

リンクを2回目にクリックしたときにのみ目的の秒が得られる理由と、hrefこれを解決するにはどうすればよいかを誰かが理解するのを手伝ってくれますか?

サーバー側で NodeJS/ExpressJS を使用しています。

4

1 に答える 1

1

href属性内で使用される関数が原因で、この問題が発生していると思います。少し前に同様の問題がありました(アプリも開発していて、ui-routerを使用していました)。問題は、タグ内で href を使用することにありました。

この質問は参考になると思います。ブラウザが空のhref属性をどのように解釈するかを知ることは重要です。

関数を他のタグで使用してみてください。たとえば、ulリストとui要素 (ng-clickディレクティブ) 内にメニューを作成します。私の場合は助かりました。

于 2014-11-05T22:42:02.877 に答える