Angular1.3路由的直接URLS问题-即使html5mode为false

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

本文关键字:即使 html5mode false 问题 URLS 路由 Angular1      更新时间:2023-11-03

如果我在链接中导航,我可以打开相应的视图,但如果我复制粘贴整个url,视图将不会加载&控制台中没有错误。

这是我对主要应用程序模块的配置

.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视图中,URL将变为(URL1)"http://localhost:8081/web/#/welcome"

  1. 如果我点击术语链接,术语视图加载在ng视图&URL变为(URL2)"http://localhost:8081/web/#/terminology"

但是,如果我将整个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视图在shell页面中,它不会像预期的那样工作,但如果它在index.html页面中,则工作正常。