Effective URL structure with nested ui-view in AngularJS

It is common knowledge that Angular functions as a SPA (Single Page Application). I am seeking the most effective approach to display a main left-side menu selector page, where clicking on any menu item will load the content in the right-side view div.

This is how I have currently implemented it:

$stateProvider
        .state('home', {
           url: '/',
           cache: false,
           templateUrl : 'resources/components/home/home.html',
            controller : 'homeController',

         }).state('main', {
            url: '/main',
           templateUrl : 'resources/components/dashboard/main.html',
            controller : 'dashboardController',


        }).state('main.profile', {
            url: '/profile',
           templateUrl : 'resources/components/clinicprofile/profile.html',
            controller : 'profileController',

My current method functions as follows...

Initially, at the homepage (/#), the login page is displayed. Once a user logs in, they are redirected to #/main where only the left menu bar is visible. When a user navigates to the profile page, the URL changes to #/main/profile due to the UI view in main.html, allowing all other views to be included within it (such as profile and setting).

What I would like to achieve is for a logged-in user to be directly redirected to /profile upon login, with the left column visible. If the user then clicks on "setting" from the left menu, they should be directed to /setting without requiring a full page reload and retaining the content of main.html on each separate page. This raises the question of the purpose of a SPA if every page includes full content like header, footer, and left menu bar. Is there a solution that allows the left column to remain while enabling users to access pages with cleaner URLs such as /profile or /setting instead of /main/profile or /main/setting?

I hope this clarifies my query.

Answer №1

A unique approach to organizing your views is by creating separate templates for the side menu, main menu, and advertisements that can be reused throughout your application. Take, for instance, the creation of a sidemenu.html file located in resources/components/dashboard, which can then be utilized in both the main and main.profile states.

 $stateProvider
        .state('home', {
           url: '/',
           cache: false,
           templateUrl : 'resources/components/home/home.html',
            controller : 'homeController',

         }).state('main', {
            url: '/main',
            views: {
                '': {
                    templateUrl : 'resources/components/dashboard/main.html',
                    controller : 'dashboardController',
                },

                'nav@main': {
                    templateUrl : 'resources/components/dashboard/sidemenu.html'
                }
            }

        }).state('profile', {
            url: '/profile',
            views: {
                '': {
                    templateUrl : 'resources/components/clinicprofile/profile.html',
                    controller : 'profileController',
                },

                '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="402e2136002d21292e6e30322f2629...">[email protected]</a>': {
                    templateUrl : 'resources/components/dashboard/sidemenu.html'
                }
            }
        });

To implement this structure, you can include the following snippets in your index.html:

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

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Angular data is being displayed and then disappears when $scope is utilized

Here is my EJS file: </head> <body data-ng-app="indexHomepage" data-ng-controller="indexController"> <div style="margin:100px;"> <h1>Express!</h1> <table data-ng-repeat="user in users"> <tr> ...

Tips for retrieving the concealed input value from the div directly preceding

Is it possible for me to retrieve the hidden input value by clicking on the text "upload profile photo"? I don't have much experience in this area. <div> <input type="hidden" value='<?php echo $list['profil ...

What's the best way to horizontally align two logos in the navigation bar?

Has anyone successfully placed 2 logos on the navbar in Materialize Framework side by side? I'm struggling to make it work and could use some help. Here is my CodePen for reference. I've experimented with the display property but haven't ...

Slider text in Master not adjusting properly for mobile devices

I am at my wits' end trying different solutions to make this work properly. The text on the slider of my homepage appears jumbled up when viewed on a mobile device. I suspect it might be related to responsive design? Could someone please take a look ...

Steps for resolving the "endless redirection loop" issue in Sharepoint

I am currently learning Javascript and working on setting up a multi-language Sharepoint site. I am trying to implement a code into each page that checks the user's email and the language in the URL (Portuguese or Spanish) and then redirects according ...

I am interested in incorporating various forms within this code

I followed an online tutorial to create this code, and I've made some edits myself, mainly related to the buttons that display information. However, I'm still learning and struggling with adding different forms to each section. I would really app ...

Modify the length of an array using a number input field

Currently, I am working with an array that contains objects and I want to dynamically change the number of objects in this array based on user input from a number type input box. Whenever the number in the input box is increased, I need to increase the len ...

Echarts: scatter plots linked with a line to the axis (resembling the PACF diagram)

I am currently working with echarts (js). Is there a method to link the dot of the scatter plot with the 0 value on the y-axis? I want it to resemble a pacf plot, similar to this example: The desired outcome should look something like this: https://i.sta ...

Embracing PWAs with subdomains – seamless installation

One of my Progressive Web Applications (PWA) called app A contains a link to another app, app B. Initially, I hosted both apps on the same subdomain (for example: ) and everything worked perfectly - installing app A also installed app B. However, when I a ...

Challenges with fading images using jQuery

I am currently working on animating a 5 image slideshow by creating a fading effect between the images rather than just switching abruptly. Here is my HTML structure: <div id="slides"> <ul class="pics"> <li><img src="imag ...

Generating multiple div elements within an AJAX iteration

Currently, I am retrieving data from the server side using AJAX. My goal is to populate data from a list of objects into divs but I am facing an issue where I cannot create the div while inside the foreach loop. $(document).ready(function () { var ...

How to use expressjs to fetch an image from a URL and show it on a webpage

I am currently running an image API from my home server, and I am working on creating a cloud-hosted page that will retrieve the image in the backend and display it, adding a layer of abstraction. My goal is to achieve the following: index.js var express ...

Create a typing effect in Javascript that mimics the user's input

Trying to simulate a typing effect with the sentence extracted from user input using JavaScript, but encountering some issues. Successfully capturing and displaying the input in the console with console.log(), however, incorporating the typing effect func ...

Is there a way to transform integers into their matching strings within Vue markup?

I have a database table where I retrieve data. The "status" field is used to manage the information in this table. If the status is equal to 1, it indicates "Active." If the status is equal to 2, it signifies "Completed." If the status is equal to 0, it r ...

Retrieve base64 encoded data from several content attributes

Is there a way to optimize the use of base64 data in CSS by defining it once and referencing it in multiple content properties? div#my_id1 { content: url(data:image/png;base64,...); } div#my_id2 { content: url(data:image/png;base64,...); } Using ...

Tips for incorporating a smooth fade in and out effect into images within a Bootstrap 5 carousel

I'm currently working with a Bootstrap 5 carousel and trying to implement a transition effect where clicking the "next" arrow will smoothly fade out the current image before fading in the next one. This is necessary because the images in my carousel v ...

Having trouble loading CSS in an express view with a router

I am encountering an issue where I am unable to load my CSS into a view that is being rendered from a Router. The CSS loads perfectly fine for a view rendered from app.js at the root of the project directory. Below is my current directory structure, node_ ...

Seamless animation when collapsing element using angular and css exclusively

I am attempting to incorporate a collapsible feature into my application. Rather than relying on external libraries like jQuery, I want to exclusively utilize Angular. For demonstration purposes, I have created a very basic example here: http://jsfiddle.n ...

PHP Notification: Attempting to access a property of an invalid type object

I am currently utilizing the Factory in AngularJS and here is the script I am using: app.factory('GetCountryService', function ($http, $q) { return { getCountry: function(str) { // The $http API is based on th ...

CSS trick for stylish arrow placement on top of a slide

Hey there! This is my first time navigating through the slick carousel functionality. I'm currently facing a challenge with adjusting the positioning of the arrow within the slider. My goal is to have the arrow displayed at the top level just like the ...