Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 使用angular ui路由,为什么我的express路由不起作用?_Angularjs_Express_Angular Ui Router - Fatal编程技术网

Angularjs 使用angular ui路由,为什么我的express路由不起作用?

Angularjs 使用angular ui路由,为什么我的express路由不起作用?,angularjs,express,angular-ui-router,Angularjs,Express,Angular Ui Router,我正在使用角度ui/ui路由。问题在于我的角度路由,或者我的服务器路由,我不知道是哪个。我的快速路线是: var compositions = require('../controllers/comptroller'); module.exports = function(Compositions, app, auth) { app.route('/critique') .post(auth.requiresLogin, compositions.cre

我正在使用角度ui/ui路由。问题在于我的角度路由,或者我的服务器路由,我不知道是哪个。我的快速路线是:

var compositions = require('../controllers/comptroller');    
module.exports = function(Compositions, app, auth) {

        app.route('/critique')
        .post(auth.requiresLogin, compositions.createCritique);

    app.route('/users')
    .get(compositions.showProfile);

    app.route('/compositions/:compositionId')
    .get(compositions.show)
    .post(auth.requiresLogin, compositions.createCritique);

    app.route('/compositions')
   // .get(compositions.profile)
    .get(compositions.all)
    .post(auth.requiresLogin, compositions.fileUpload);
我的角度路由是这样的:

$stateProvider
  .state('all compositions', {
    url: '/compositions/recent',
    templateUrl: 'compositions/views/list.html'
  }).
state('create comp', {
    url: '/compositions/create',
    templateUrl: 'compositions/views/create.html',
     resolve: {
            loggedin: checkLoggedin
        }
}).
state('myuser', {
    url: '/users',
    templateUrl: 'compositions/views/profile.html',
     resolve: {
            loggedin: checkLoggedin
        }
}).
我使用状态机来处理路由。当我导航到localhost:3000/#/用户我收到我的profile.html模板,这是我想要的。然而,我的快速路线上的GET请求从未被调用。我正在尝试获取函数“showProfile”,但它从未命中函数。除非我导航到localhost:3000/users,否则会调用函数showProfile,但不会调用模板profile.html。有人能告诉我我做错了什么吗?我需要使用showProfile函数来查询我的mongo数据库。感谢您的任何建议或帮助


编辑:值得注意的是,如果我将compositions.showProfile放在另一个app.route中,我会点击后端函数,然后加载模板。对于这条路线,/用户,它似乎不起作用

当您点击
localhost:3000/#/用户
,浏览器转到
localhost:3000
并请求
/
。哈希值(
#!/users
)永远不会发送到web服务器。客户端路由器使用它来决定加载哪个模板。@AnthonyChu但是当我转到localhost:3000/用户时,与localhost:3000/#相比,我得到的结果是不同的/用户这是预期的。考虑这一点的一种方式是将
发送到服务器之前的部分,
以及之后的任何部分都不会发送到服务器。对于
localhost:3000/users
,浏览器正在从服务器请求
/user
资源,该资源与express中的
/users
路由匹配。@AnthonyChu so,你知道我将如何修复它,使它不会根据#是否存在而请求资源吗?
/users
做什么?通常,您会让客户端路由加载模板,然后向服务器发出REST调用,以检索要在模板中呈现的数据。