根URL更改时重定向到不同的路由

时间:2014-04-20 14:24:50

标签: javascript html node.js angularjs

我正在开发anuglar + nodejs app并遇到这个问题。我想设置以下网址映射:

  1. localhost:3000 / =>节点服务器在服务器端提供index.html,然后在客户端提供anuglar服务部分视图index.html(在服务器端有一个客户端有两个index.html) localhost:3000 / signup => angular routeProvider提供部分视图signup.html到index.html(ajax所以没有重新加载)

  2. localhost:3000 / customerLoggedin =>节点服务器提供customerLoggedin.html,而angular可能会提供其他部分(页面重新加载) localhost:3000 / customerLoggedin / order-form => angular routeProvider提供部分视图order.html(ajax)

  3. 我有以下代码:

    棱角面:

    system.js:

    angular.module('myApp.system').config(['$stateProvider', '$urlRouterProvider','$locationProvider',
            function($stateProvider, $urlRouterProvider,$locationProvider) {
                // For unmatched routes:
                $urlRouterProvider.otherwise('/');
                // states for my app
                $stateProvider.state('home', {
                        url: '/',
                        templateUrl: 'public/system/views/partials/index.html' // there are two index.html one on the server side (which is the layout) and one served by angular
                    }).state('signup',{
                    url:'/signup',
                        templateUrl:'public/system/views/partials/signup.html'
                    }).state('payment',{
                        url:'/payment',
                        templateUrl:'public/system/views/partials/payment.html',
                        controller:'paymentCtrl'
                    }).state('order',{
                        url:'/order-form',
                        templateUrl:'public/system/views/partials/order.html',
                        controller:'orderCtrl'
                    });
            }
        ])
    

    customerLoggedin.html:

       ...
       <a href='/order-form'><span>New Order</span></a>
       ...
       <section data-ui-view ng-view class='view-animate'/>
       ...
    

    节点服务器上的路由:

    module.exports = function(app){
        app.get('/customerLoggedIn',function(req,res){
            res.render('customerLoggedIn');
            });
    
            app.get('/',function(req,res){
            res.render('index');
            });
    
    };
    

    现在问题是当我点击customerLoggedin.html中的“新订单”链接时,angular给了我client-sdie index.html,它应该只显示在localhost:3000 / index.html中。我希望angular能够将部分视图order.html提供给customerLoggedin.html

    中的ngview

    如何实现这一目标?

    提前致谢

1 个答案:

答案 0 :(得分:0)

尝试使用ui-sref指令来触发状态更改,而不是指向网址

<a ui-sref='order'>New Order</a>
相关问题