简体   繁体   English

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

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

If I'm navigating through the links, I'm able to open the respective views but if I copy paste the entire url, view is not loading & no errors in console. 如果我浏览链接,我可以打开相应的视图,但如果我复制粘贴整个网址,则视图未加载且控制台中没有错误。

Here is my config of main app module, 这是我的主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);
    }]);;

Eg: 1. If I click on home link, welcome view is loading in ng-view and the URL becomes (URL1) " http://localhost:8081/web/#/welcome " 例如:1。如果我点击主页链接,欢迎视图将在ng-view中加载,URL将变为(URL1)“ http:// localhost:8081 / web /#/ welcome

  1. If I click on terms link, terminology view is loading in ng-view & the URL becomes (URL2) " http://localhost:8081/web/#/terminology " 如果单击术语链接,术语视图将在ng-view中加载,URL将变为(URL2)“ http:// localhost:8081 / web /#/术语

but If I copy paste the entire URL in a new tab, the view becomes blank. 但如果我复制粘贴整个URL在新选项卡中,视图将变为空白。 There is no error in the console. 控制台中没有错误。 I'm using Angular1.3 我正在使用Angular1.3

ADDED: Moreover, for the first time also default view is not loading... Thanks in advance 补充:此外,第一次默认视图也没有加载...提前谢谢

I found the solution for this. 我找到了解决方案。 My actual index.html file is like this 我的实际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>

now I replaced the content of shell.html to the above ng-include directive(line), then everything works fine. 现在我将shell.html的内容替换为上面的ng-include指令(行),然后一切正常。

Can anyone tell me why this is happening? 谁能告诉我为什么会这样? If ng-view is inside shell page, its not working as expected but if it is in index.html page its working fine. 如果ng-view在shell页面内,它不能按预期工作,但如果它在index.html页面中工作正常。

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

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