0

Setting up routing for the multi-tenant frontend application using AngularJs and UI-Router.

For an example when a user type the following URL the dashboard should be loaded for userxyz and the parameter must be maintained in the user's browser through session, so that the user should be able to browse other hyperlinks within application.

http://servername.com/#/dashboard/userxyz

Am struggling to achieve this, I have watched some tutorials but unable to understand.

Here is the code for my route configuration.

(function () {
    'use strict';

    app.config(["$stateProvider", "$urlRouterProvider",
        function ($stateProvider, $urlRouterProvider) {
            $stateProvider
                .state("dashboard", {
                    url: "/dashboard/{tenantid}",
                    templateUrl: "app/components/dashboard/dashboardView.html",
                    controller: "DashboardController"
                })

                .state("people", {
                    url: "/people/{tenantid}",
                    templateUrl: "app/components/people/peopleView.html",
                    controller: "PeopleController"
                })

                .state("contact", {
                    url: "/contact/{tenantid}",
                    templateUrl: "app/components/contact/contactView.html",
                    controller: "ContactController"
                })

                $urlRouterProvider.otherwise("/dashboard/{tenantid}");
        }]);
})();

In my index.html, I have the following code to display the state in ui-view:

<div class="row" ui-view>

</div>

And, I did manage to setup the hyperlinks using ui-sref, here how it is:

<a ui-sref="dashboard">Home</a>
<a ui-sref="people">People</a>
<a ui-sref="contact">Contact</a>
4
  • 1
    why not save the tenantid in the session or local storage ? Commented Dec 3, 2015 at 12:54
  • I wouldn't mind giving that a try! The session or local storage will be stored in the browser until the browser is closed? If yes what exactly do you recommend? By the way, I don't have a login page for this application and may not have. This is a client facing application. Commented Dec 3, 2015 at 12:59
  • the sessionStorage will remain until you close the tab or browser but the localStorage will stated after that, use what you need wisely :D Commented Dec 3, 2015 at 13:14
  • I have tried configuring '$localStorage' service from 'ngStorage' but it doesn't work as well. The value gets reset when the hyperlink is clicked. If you have time, can you please provide me an example? :) Commented Dec 3, 2015 at 14:52

1 Answer 1

1

Better user local o session storage for save the tenant

According with the comments before:

If you don't need support for ie7 (hope so), try to use the native browser localStorage, for insert an item localStorage.setItem('key', 'value') for retrieve localStorage.getItem('key')

see the localStorage browser support here Local Storage Browser Support

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

1 Comment

Am grabbing the tenant from the landing page (dashboard based on an example) then stored in the local storage. This information is being retrieved on the respective controllers throughout the application. Thanks for the help! :)

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.