ionic设置html5model后,无法正常显示页面,在线等,急

这是一个奇怪的问题,当我设置了HTML5MODEL之后,无法正常访问页面

第一步 设置HTML
<base href="/test/ionic/">
或者
<base href=".">
第二步 开启HTML5MODEL
$locationProvider.html5Mode(true);
第三步 设置apache .htaccess
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /test/ionic/
    RewriteRule ^index\.html$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /test/ionic/index.html [L]
 </IfModule>

设置完成后,刷新首页,能够正常访问首页
但是在点击 ion-tabs 里面的其他任何链接的时候,就无任何反应

如下代码运行后具体步骤为:

  • 直接访问首页 app/home ,正常

  • 点击 about ,无任何反应

  • 直接访问 app/about ,也正常

值得说明的是,如果不用ionic,那么就可以完全正常的访问任何一个链接

完整的代码


<html ng-app="ionicApp">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">

    <title>Tabs Example</title>
    <base href="/test/ionic/">
    <link href="../../m/bower_components/ionic/release/css/ionic.min.css" rel="stylesheet">
    <script src="../../m/bower_components/ionic/release/js/ionic.bundle.min.js"></script>
</head>

<body>

<ion-nav-bar class="bar-positive">
    <ion-nav-back-button>
    </ion-nav-back-button>
</ion-nav-bar>

<ion-nav-view></ion-nav-view>


<script id="templates/tabs.html" type="text/ng-template">
    <ion-tabs class="tabs-icon-top tabs-positive">

        <ion-tab title="Home" icon="ion-home" ui-sref="app.home">
            <ion-nav-view name="home-tab"></ion-nav-view>
        </ion-tab>

        <ion-tab title="About" icon="ion-ios-information" ui-sref="app.about">
            <ion-nav-view name="about-tab"></ion-nav-view>
        </ion-tab>

        <ion-tab title="Contact" icon="ion-ios-world" ui-sref="app.contact">
            <ion-nav-view name="contact-tab"></ion-nav-view>
        </ion-tab>

    </ion-tabs>
</script>

<script id="templates/home.html" type="text/ng-template">
    <ion-view view-title="Home">
        <ion-content class="padding">
            <p>
                <a class="button icon icon-right ion-chevron-right" ui-sref="app.facts">Scientific Facts</a>
            </p>
        </ion-content>
    </ion-view>
</script>

<script id="templates/facts.html" type="text/ng-template">
    <ion-view view-title="Facts">
        <ion-content class="padding">
            <p>Banging your head against a wall uses 150 calories an hour.</p>
            <p>Dogs have four toes on their hind feet, and five on their front feet.</p>
            <p>The ant can lift 50 times its own weight, can pull 30 times its own weight and always falls over on its right side when intoxicated.</p>
            <p>A cockroach will live nine days without it's head, before it starves to death.</p>
            <p>Polar bears are left handed.</p>
            <p>
                <a class="button icon ion-home" ui-sref="app.home"> Home</a>
                <a class="button icon icon-right ion-chevron-right" ui-sref="app.facts2">More Facts</a>
            </p>
        </ion-content>
    </ion-view>
</script>

<script id="templates/facts2.html" type="text/ng-template">
    <ion-view view-title="Also Factual">
        <ion-content class="padding">
            <p>111,111,111 x 111,111,111 = 12,345,678,987,654,321</p>
            <p>1 in every 4 Americans has appeared on T.V.</p>
            <p>11% of the world is left-handed.</p>
            <p>1 in 8 Americans has worked at a McDonalds restaurant.</p>
            <p>$283,200 is the absolute highest amount of money you can win on Jeopardy.</p>
            <p>101 Dalmatians, Peter Pan, Lady and the Tramp, and Mulan are the only Disney cartoons where both parents are present and don't die throughout the movie.</p>
            <p>
                <a class="button icon ion-home" ui-sref="app.home"> Home</a>
                <a class="button icon ion-chevron-left" ui-sref="app.facts"> Scientific Facts</a>
            </p>
        </ion-content>
    </ion-view>
</script>

<script id="templates/about.html" type="text/ng-template">
    <ion-view view-title="About">
        <ion-content class="padding">
            <h3>Create hybrid mobile apps with the web technologies you love.</h3>
            <p>Free and open source, Ionic offers a library of mobile-optimized HTML, CSS and JS components for building highly interactive apps.</p>
            <p>Built with Sass and optimized for AngularJS.</p>
            <p>
                <a class="button icon icon-right ion-chevron-right" ui-sref="app.navstack">Tabs Nav Stack</a>
            </p>
        </ion-content>
    </ion-view>
</script>

<script id="templates/nav-stack.html" type="text/ng-template">
    <ion-view view-title="Tab Nav Stack">
        <ion-content class="padding">
            <p><img src="http://ionicframework.com/img/diagrams/tabs-nav-stack.png" style="width:100%"></p>
        </ion-content>
    </ion-view>
</script>

<script id="templates/contact.html" type="text/ng-template">
    <ion-view title="Contact">
        <ion-content>
            <div class="list">
                <div class="item">
                    @IonicFramework
                </div>
                <div class="item">
                    @DriftyTeam
                </div>
            </div>
        </ion-content>
    </ion-view>
</script>



<script type="text/javascript">

    angular.module('ionicApp', ['ionic'])

            .config(function($stateProvider, $urlRouterProvider,$ionicConfigProvider,$locationProvider) {

                $locationProvider.html5Mode(true);

                $ionicConfigProvider.platform.ios.tabs.style('standard');
                $ionicConfigProvider.platform.ios.tabs.position('bottom');
                $ionicConfigProvider.platform.android.tabs.style('standard');
                $ionicConfigProvider.platform.android.tabs.position('standard');

                $ionicConfigProvider.platform.ios.navBar.alignTitle('center');
                $ionicConfigProvider.platform.android.navBar.alignTitle('left');

                $ionicConfigProvider.platform.ios.backButton.previousTitleText('').icon('ion-ios-arrow-thin-left');
                $ionicConfigProvider.platform.android.backButton.previousTitleText('').icon('ion-android-arrow-back');

                $ionicConfigProvider.platform.ios.views.transition('ios');
                $ionicConfigProvider.platform.android.views.transition('android');

                $stateProvider
                        .state('app', {
                            url: "/app",
                            abstract: true,
                            templateUrl: "templates/tabs.html"
                        })
                        .state('app.home', {
                            url: "/home",
                            views: {
                                'home-tab': {
                                    templateUrl: "templates/home.html",
                                    controller: 'HomeTabCtrl'
                                }
                            }
                        })
                        .state('app.facts', {
                            url: "/facts",
                            views: {
                                'home-tab': {
                                    templateUrl: "templates/facts.html"
                                }
                            }
                        })
                        .state('app.facts2', {
                            url: "/facts2",
                            views: {
                                'home-tab': {
                                    templateUrl: "templates/facts2.html"
                                }
                            }
                        })
                        .state('app.about', {
                            url: "/about",
                            views: {
                                'about-tab': {
                                    templateUrl: "templates/about.html"
                                }
                            }
                        })
                        .state('app.navstack', {
                            url: "/navstack",
                            views: {
                                'about-tab': {
                                    templateUrl: "templates/nav-stack.html"
                                }
                            }
                        })
                        .state('app.contact', {
                            url: "/contact",
                            views: {
                                'contact-tab': {
                                    templateUrl: "templates/contact.html"
                                }
                            }
                        });


                $urlRouterProvider.otherwise("/app/home");

            })

            .controller('HomeTabCtrl', function($scope) {
                console.log('HomeTabCtrl');
            });

</script>
</body>
</html>
回复
阅读 2.7k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
宣传栏