I have an extremely strange situation with ui-router. I have a state defined like so:
我对ui-router有一个非常奇怪的情况。我有一个像这样定义的状态:
.state('profileQuestion', {
url: '/profile-questions/:profileQuestionId',
templateUrl: 'client/users/views/profile-question.ng.html',
controller: 'profileQuestionCtrl'
})
It works fine and dandy as I navigate through the app. However, if I go straight to this page, for example localhost:3000/profile-questions/1
, the app does not recognize the page, and immediately tries to go to the otherwise
route.
当我浏览应用程序时,它工作正常,花花公子。但是,如果我直接访问此页面,例如localhost:3000 / profile-questions / 1,则应用程序无法识别该页面,并立即尝试转到其他路径。
$urlRouterProvider.otherwise('/login');
What's more, it actually goes to /profile-questions/login
instead of just /login
! The controller for profile-questions never gets called. So in sum, this ui router works fine when I navigate to the page from another, but fails when I load the page by itself. I should add that if I remove the state parameter options :profileQuestionId
, the /profile-questions
route loads correctly. Any ideas?
更重要的是,它实际上是/ profile-questions / login而不仅仅是/ login!用于配置文件问题的控制器永远不会被调用。总而言之,当我从另一个页面导航到该页面时,这个ui路由器工作正常,但是当我自己加载页面时失败了。我应该补充一点,如果我删除状态参数选项:profileQuestionId,/ profile-questions路由正确加载。有任何想法吗?
1 个解决方案
#1
0
As @Radim Kohler and @Joe Lloyd suggested, the issue is that HTML5 mode was turned on. I see now that the server thinks I am looking for something in the /profile-questions/ directory - which doesn't exist. To fix this, I just changed it to be a query string parameter like so:
正如@Radim Kohler和@Joe Lloyd所说,问题是HTML5模式已经打开。我现在看到服务器认为我在/ profile-questions /目录中寻找一些东西 - 它不存在。为了解决这个问题,我只是将其更改为查询字符串参数,如下所示:
.state('profileQuestion', {
url: '/profile-question?profileQuestionId',
templateUrl: 'client/users/views/profile-question.ng.html',
controller: 'profileQuestionCtrl'
})
#1
0
As @Radim Kohler and @Joe Lloyd suggested, the issue is that HTML5 mode was turned on. I see now that the server thinks I am looking for something in the /profile-questions/ directory - which doesn't exist. To fix this, I just changed it to be a query string parameter like so:
正如@Radim Kohler和@Joe Lloyd所说,问题是HTML5模式已经打开。我现在看到服务器认为我在/ profile-questions /目录中寻找一些东西 - 它不存在。为了解决这个问题,我只是将其更改为查询字符串参数,如下所示:
.state('profileQuestion', {
url: '/profile-question?profileQuestionId',
templateUrl: 'client/users/views/profile-question.ng.html',
controller: 'profileQuestionCtrl'
})