Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use $urlRouterProvider.rule #2342

Closed
kingsleywang opened this issue Oct 28, 2015 · 2 comments
Closed

How to use $urlRouterProvider.rule #2342

kingsleywang opened this issue Oct 28, 2015 · 2 comments

Comments

@kingsleywang
Copy link

Code here is as an example: address bar is changed but state2,html is not loaded

You just can see a empty page without throwing any errors

(function(){
    'use strict';
    angular.module('myapp', [ 'ui.router' ])
            .config(function($stateProvider, $urlRouterProvider){
            $urlRouterProvider.otherwise("/state1");
            $urlRouterProvider.rule(function ($injector, $location) {
                return "/state2";
            });

            $stateProvider
                .state('state1', {
                    url: "/state1",
                    views: {
                        "mainview": { template: "state1.html" }
                    }
                })
                .state('state2', {
                    url: "/state2",
                    views: {
                        "mainview": { template: "state2.html" }
                    }
                });
        })

        .controller('AppCtrl', AppCtrl);
          function AppCtrl(){
        }
})();
@kingsleywang
Copy link
Author

Here is my index.html

<!doctype html>

<html ng-app="myapp">

    <head lang="en">

        <meta charset="UTF-8"/>

        <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" />

        <title>Test</title>

        <link rel="stylesheet" href="app.css">

    </head>

    <body ng-controller="AppCtrl as appCtrl">

        <div ui-view="mainview"></div>

        <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js"></script>

        <script src="https://cdn.jsdelivr.net/angular.ui-router/0.2.15/angular-ui-router.min.js"></script>

        <script src="app.js"></script>

    </body>

</html>

@eddiemonge
Copy link
Contributor

You have an infinite loop going on

http://plnkr.co/edit/EeA1lh59YGoy1EQG7ZLV?p=preview

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants