【问题标题】:Routing issue with angularjs while version update版本更新时angularjs的路由问题
【发布时间】:2019-09-03 09:23:31
【问题描述】:

场景:我已将当前的 angularjs 版本从 AngularJS v1.5.5 更新到 AngularJS v1.5.7。应用程序工作正常,但 URL 路由存在问题,它的行为有所不同。让我们看看下面的验收标准。

试试 1

原始网址如下,这也是预期的结果。

https://u-unalytix.milestoneinternet.com/Unalytix.Web.UAT/dashboard/marketing-channels

就在更新版本之后,我在下面的注释行中遇到了错误。

$locationProvider.html5Mode(true);  
// $urlrouterprovider.rule(function ($injector, $location) {
       // var path = $location.path();
       // if (path != '/' && path.slice(-1) === '/') {
          // $location.replace().path(path.slice(0, -1));
       // }
// });

结果

https://u-unalytix.milestoneinternet.com/U/dashboard/marketing-channels

你可以在这里看到由于某种原因我们没有得到预期的结果。然后我尝试使用 module.config 中的另一个代码。谷歌搜索后,我得到了一些解决此问题的答案,我尝试如下但仍然无法得到预期的结果。

试试 2

我尝试使用这段代码仍然无法得到预期的结果。

$locationProvider.html5Mode({
    enabled: false,
    requireBase: true
});

结果

这次在 URL 中获取 /#

https://u-unalytix.milestoneinternet.com/Unalytix.Web.UAT/#/dashboard/marketing-channels

不知道这个问题。如果有人对此问题有任何想法,请与我分享。

【问题讨论】:

    标签: angularjs angular-ui-router url-routing angularjs-routing


    【解决方案1】:

    要实现这一点,您需要进行两项更改。

    1. 将此添加到您的配置中。
    $locationProvider.html5Mode(true);
    $locationProvider.hashPrefix('');
    
    1. 在 index.html 头标签中添加应用程序的基础
    <head>
    ...
    
      <base href='/' />
    
    ...
    </head>
    

    【讨论】:

    • 查看您的网址,似乎基本网址是 Unalytix.Web.UAT。如果上述解决方案不起作用,请更改为
    猜你喜欢
    • 2016-11-09
    • 2014-08-21
    • 2015-04-20
    • 1970-01-01
    • 1970-01-01
    • 2021-01-01
    • 2017-05-01
    相关资源
    最近更新 更多