繁体   English   中英

即使在html5mode为false时,也会出现Angular1.3路由的直接URLS问题

[英]Issue with direct URLS of Angular1.3 routing - even when html5mode is false

如果我浏览链接,我可以打开相应的视图,但如果我复制粘贴整个网址,则视图未加载且控制台中没有错误。

这是我的主app模块的配置,

.config(['$locationProvider', '$routeProvider', function ($locationProvider, $routeProvider) {

        $routeProvider
                .when('/welcome', {
                    templateUrl: 'src/app/welcome/welcome.html'
                })
                .when('/terminology', {
                    controller: 'TermsController',
                    controllerAs: 'vm',
                    templateUrl: 'src/app/terminology/term-table.html'
                })
                .when('/', {
                    redirectTo: '/welcome'
                })
                .otherwise({
                    redirectTo: '/welcome'
                });

                $locationProvider.html5Mode(false);
    }]);;

例如:1。如果我点击主页链接,欢迎视图将在ng-view中加载,URL将变为(URL1)“ http:// localhost:8081 / web /#/ welcome

  1. 如果单击术语链接,术语视图将在ng-view中加载,URL将变为(URL2)“ http:// localhost:8081 / web /#/术语

但如果我复制粘贴整个URL在新选项卡中,视图将变为空白。 控制台中没有错误。 我正在使用Angular1.3

补充:此外,第一次默认视图也没有加载...提前谢谢

我找到了解决方案。 我的实际index.html文件是这样的

<html class="no-js" lang="en" ng-app="app">
<head>  
    <!-- my css files -->
</head>
<body>
    <!-- this shell page contains "ng-view" directive which is causing the whole problem -->
    <div ng-include="'src/app/igl-layout/shell.html'"></div>

    <!-- my js files -->
</body>

现在我将shell.html的内容替换为上面的ng-include指令(行),然后一切正常。

谁能告诉我为什么会这样? 如果ng-view在shell页面内,它不能按预期工作,但如果它在index.html页面中工作正常。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM