0

I have made one state and trying to navigate to other page. There is no error in console but navigation is not working either.

index.html

<body ng-app="app">
    <a href='#/first-msg'>link</a>
    <div ui-view></div>

    <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.3/angular.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.4.2/angular-ui-router.js"></script>
    <script src="application.js"></script>
</body>

application.js

var app = angular.module('app', ['ui.router']);
app.config(['$stateProvider', '$locationProvider', function($stateProvider, $locationProvider) {
    $stateProvider.state('firstMessage', {
        url: '/first-msg',
        templateUrl: 'home.html',
        controller: 'homeCtrl'
    });
    $locationProvider.html5Mode({
        enabled: true,
        requireBase: false
    });
}]);
app.controller("homeCtrl", ['$scope', function($scope) {
    $scope.message = "This is home";
}]);

when i click on link, the url is like

.../index.html#%2Ffirst-msg
0

1 Answer 1

3

Using ui-router, you should not use href. Use ui-sref instead:

<a ui-sref="firstMessage">link</a>

Note I use the state name, and not its URL.


JSFiddle demo

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.