Angularjs UI路由器$stateParams初始值为空";“无效”;路由页面加载

Angularjs UI路由器$stateParams初始值为空";“无效”;路由页面加载,angularjs,angular-ui-router,Angularjs,Angular Ui Router,我的appConfig中有以下代码重定向/转换逻辑,用于重新指向无效路由: $urlRouterProvider.when('/:lang/profile/:keywords/:id', ['$state', '$stateParams', function ($state, $stateParams) { $state.transitionTo('root.public-profile.summary', $stateParams, { relo

我的appConfig中有以下代码重定向/转换逻辑,用于重新指向无效路由:

$urlRouterProvider.when('/:lang/profile/:keywords/:id', ['$state', '$stateParams', function ($state, $stateParams) {
            $state.transitionTo('root.public-profile.summary', $stateParams, {
            reload: true,
            inherit: false,
            notify: true
        });
摘要路线定义为:

state('root.public-profile.summary', {
                    url: "/summary",
                    templateUrl: "/templates/public.profile.summary.tpl.html"
            })
因此,当用户试图访问“/:lang/profile/:keywords/:id”时,它应该将它们重定向/重新指向/:lang/profile/:keywords/:id/summary。如果用户试图从Url中删除“摘要”部分,则它会按照预期自动重新追加。但是,如果用户直接在新浏览器窗口中复制并粘贴“错误”链接,$stateParams对象为空,因此无法进行转换

这种行为是故意的吗?有没有办法解决这个问题?

你说得对

这种行为是设计出来的。你应该以状态图的形式看到一切,转换是否会发生取决于激活的状态。我从你的代码片段中可以看到,你正在使用ui路由器,其中状态比实际URL更重要。 不确定你想要达到什么目标,但这些文档对你很有帮助。


如果您确信此答案,请对任何其他问题进行回复或投票支持。

Gautam感谢您的回复。我试图实现的基本目标是,如果用户碰巧共享无效/部分url,则自动将其重定向到正确的url。不确定如何完成。请查看此文档中routeprovider中------Others()方法的说明。将帮助您筛选出所有无效的URL并使用所需的URL。谢谢