Click here to Skip to main content
15,905,011 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi ,

We are facing issue with angularJs SPA, the problem seems to be with routing to the #fragments in same page when using ui-router. We configured the routes and menu items like below,

HTML
<a ui-sref="home" ng-click="CloseDrawer()"><span>Services</span></a>
<a ui-sref="map" ng-click="CloseDrawer()">^__i class="fa fa-fw fa-rupee"><span>Map</span></a>

Java
app.config(function ($stateProvider, $urlRouterProvider) {

    $urlRouterProvider.otherwise('home');

    $stateProvider
       .state('home',
        {
            url: '#home',
            templateUrl: 'Templates/home.html'
        }).state('services',
        {
            url: '#services',
            templateUrl: 'Templates/home.html'
        }).state('pricing',
        {
            url: '#map',
            templateUrl: 'Templates/home.html',
            controller: 'mapController'
        });
});

upon click on anchor tag, based on routes router is redirecting.
My index.html / main page for SPA looks some thing like below
HTML
<body id="_body" ng-controller="RootCtrl" ng-class="DrawerClass">
    <div id="main" class="container_m">
        <!--Drawer-->
        <my_drawer></my-drawer>

        <div class="content-wrap" ng-click="CloseDrawer()">
            <div class="content">
                <!--Header is custom directive-->
                <my-header></my-header>
                <!--Main part where views will be rendered-->
                <ui-view></ui-view>
            </div>
            <!--Footer is custom directive-->
            <my-footer></my-footer>
        </div>
    </div>


and home.html looks like below
HTML
<section id='home'>
.
.
</section>
<section id='services'>
.
.
</section>
<section id='map'>
.
<!--map goes here-->
.
<map></map>
.
</section>


The problem is, when ever we click on any link from menu, the controller associated with the map route is firing its init() and the url is forming like '/#/home#map'. please notice 2 hash fragments in url.

and we are initializing the map from RootController init() which is on body tag and as we click on map menu item map disappearing.

We are unable to figure out,the #fragment redirection (in Same page, with diff Divs) when using ui-router in SPA and what causing MAP to disappear in this case?

Thanks in Adv,
Harry

What I have tried:

Tried removing controller from route config and placed on map div but no use. placed hash in route as some of blog discussions suggested, to avoid extra redirection in ui-sref="#/services" but no use.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900