使用ui.router sref的奇怪行为

时间:2021-10-29 19:40:57

Feel like i'm going insane ..

觉得我疯了......

{
    state: 'solicitation.details',
    config: {
        url: '/details/:stype',
        parent: 'solicitation',
        templateUrl: function ($stateParams) {
            return 'app/solicitation/templates/' + $stateParams.stype + '.html';
        },
        controller: 'DetailsController',
        controllerAs: 'dc',
        title: 'Solicitation Details'
    }
},

And it gets generated like this for stype=request:

它为stype = request生成如下:

<a ng-class="vm.disable.details ? 'disabled' : ''" class="btn btn-default" href="#/solicitation/self/details/request" role="button" ui-sref="solicitation.details({type: vm.type})">Details</a>

On click I get an error:

点击后我收到一个错误:

Warning: Error routing to Solicitation Details. Cannot GET /app/solicitation/templates/.html

警告:错误路由到征集详细信息。不能GET /app/solicitation/templates/.html

If i input the route manually in to the browser (http://xxxx.com/#/solicitation/self/details/request) it works .. WTF

如果我手动输入路线到浏览器(http://xxxx.com/#/solicitation/self/details/request)它的工作原理.. WTF

Added a console.log to templateUrl function:

为templateUrl函数添加了console.log:

templateUrl: function ($stateParams) {
    var stype = $stateParams.stype;
    console.log(stype);
    return 'app/solicitation/templates/' + stype + '.html';
},

Output:

request //STYPE ACTUALLY GETS POPULATED
solicitation.route.js:58 
angular.js:9866 GET http://localhost:3000/app/solicitation/templates/.html 404 (Not Found)
angular.js:11655 Warning: Error routing to Solicitation Details. Cannot GET /app/solicitation/templates/.html

1 个解决方案

#1


If I remember correctly, you shouldn't be using the href tag as ui-router only relies on ui-sref for routing.

如果我没记错的话,你不应该使用href标签,因为ui-router只依赖于ui-sref进行路由。

#1


If I remember correctly, you shouldn't be using the href tag as ui-router only relies on ui-sref for routing.

如果我没记错的话,你不应该使用href标签,因为ui-router只依赖于ui-sref进行路由。