angular-ui-router: breadcrumbs working fine, but issues with displaying views

This is the code for my app's router.js:

agentRouter.config([
    '$stateProvider',
    '$urlRouterProvider',
    function($stateProvider, $urlRouterProvider) {
 var root = {
        name: 'root',
        abstract: true,
        url: '',
        title: 'home',
        views: {
            'header':   { templateUrl: 'views/headers/header.app.html', controller: 'HeaderCtrl' },
            'body':     { templateUrl: "views/root.html" },
            'footer':   { templateUrl: 'views/footers/footer.app.html' }
        }
    }; 
        var agent = {
            name: 'root.agent',  
            url: '/agent',      
            title: 'agent',   
            views: {
                'root.sidebar':     { templateUrl: "views/main.sidebar.html" },
                'root.container':   { templateUrl: "views/partials/agent/list.container.html" }
            }
        };
        var detail = {
            name: 'root.agent.detail', 
            url: '/detail/:id',
            title: 'agentDetail',      // used for breadcrumb
            views: {
                'root.sidebar':     { templateUrl: "views/main.sidebar.html" },
                'root.container':   { templateUrl: "views/partials/agent/list.chantier.html" }
            }
        };
        /.../
       
        $stateProvider.state(root);
        $stateProvider.state(agent);
        $stateProvider.state(detail);
    }
]);

This is the content of my root.html :

<!--Breadcrumb content-->

<ul class="row breadcrumb">
    <i class="glyphicon glyphicon-home" style=""></i>
    <li ng-repeat="state in $state.$current.path">
        <a ng-href="#{{state.url.format($stateParams)}}"><span ng-bind="state.title"></span></a>
        <span ng-hide="$last" class=""></span>
   </li>
</ul>

 <!--Sidebar content-->
 <div ui-view="root.sidebar">default root.sidebar</div>

    <!--Container content-->
   <div style="background-color: #f9f9f9" ui-view="root.container">default root.container</div>

I am able to access my "agent" page (a list of people) and my breadcrumb displays correctly as : home / agent

However, when I click on an item from the list, I always end up on the same page but my breadcrumb shows correctly as: home / agent / agentDetail

If I change the detail section in app.router.js like this :

var detail = { name: 'root.detail', // initial reference + detail (child) url: '/agent/detail/:id', // reference used in HTML files, be cautious it's a continuation of the previous URL!!! title: 'agentDetail', // reference used for breadcrumb views: { 'root.sidebar': { templateUrl: "views/main.sidebar.html" }, 'root.container': { templateUrl: "views/partials/agent/list.chantier.html" } } };

I get the correct page (list.chantier.xml) but the breadcrumb is incorrect:

home / agentDetail instead of home / agent / agentDetail

I would like to have the accurate breadcrumb display (home / agent / agentDetail) along with the correct page (list.chantier.html) when clicking on an item from the agent list page (list.container.html)

Thank you in advance for your assistance

Answer №1

When you rename the state to 'root.detail', you are actually connecting the detail state to the root state, hence seeing 'home / agentDetail' in the breadcrumb is completely expected.

You may want to check out the angular-breadcrumb module for more features, such as interpolation in breadcrumb labels and an option to adjust the parent of the state specifically for the breadcrumb.

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

Leveraging node modules in the browser using browserify - Error: fileType is not recognized

I am currently attempting to utilize the file-type npm package directly in my browser. Despite my efforts, I have encountered an error when trying to run the example code: Uncaught ReferenceError: fileType is not defined (Example code can be found here: ...

Show and hide iframe using jQuery

I am attempting to toggle the visibility of an iframe using a button or anchor element. I found a fiddle created by Sethen posted in this answer, and used it to create my own version. It works perfectly with jQuery 1.8.3, but when I try to use a newer ver ...

jQuery Multi-select - Event Handler for Selecting All Items

I am currently using a jQuery multiselect that has the select all option checked by default. When there is a change in the selected options, I reload the page data accordingly. Everything is working well except for the fact that clicking the 'Select ...

Error: HTML code being displayed instead of form value in Ajax request output

For the past couple of days, I've been struggling with an Ajax issue that I just can't seem to figure out. Despite looking for a solution online, nothing seems to work. Below is the code snippet that's causing me trouble: <!DOCTYPE html& ...

Convert a JSON array with a single element into a valid JavaScript object

Within my programming scripts, I frequently utilize PHP arrays with numeric keys. However, these keys are not necessarily sequential from 0 to n; they can be randomly chosen. Specifically, I am working on a script that organizes scheduled events at specifi ...

Showing a progress bar within a gulp pipeline

Can the progress bar be shown in gulp when transferring specific files? gulp.task('release:step-2', function() { return gulp.src(config.copy_src, { dot: true }) .pipe(gulp.dest(config.path.dest.app)); }); ...

Guide: Generating a DIV Element with DOM Instead of Using jQuery

Generate dynamic and user-defined positioning requires input parameters: offsetHeight, offsetLeft, offsetParent, offsetTop, offsetWidth ...

Clarification on the order and frequency of AJAX XHR request onReadyStateChange events

Currently, I am in the process of learning how to create a basic stock quote tool using Python-Flask and Javascript. I have a specific interest in mastering plain Javascript. While my code is functional, I am puzzled by the fact that I receive 3 error mes ...

Translating a few lines of JavaScript into C#

I'm looking to convert some code from JavaScript to C#, but I'm having trouble grasping a certain section... function getHisto(pixels) { var histosize = 1 << (3 * sigbits), histo = new Array(histosize), inde ...

Serve different files using Node.js socket.io webserver, not just index.html

I recently started delving into socket.io and decided to use this chat example as a reference. As I navigate to ip:8080/public/index.html, I realize the need to access other files, such as additional JS scripts that will be used on the client side in the ...

Transforming a massive JSON object into a Blob concerns directly converting it into an ArrayBuffer or Blob to prevent exceeding the maximum string length error

Situation: Within my application, I am encountering the following code: let blob = new Blob([JSON.stringify(json)], {type: "application/json"}); This code sometimes fails because the maximum string length allowed in Chrome is approximately 500M ...

Update database upon drag-and-drop using jQuery

I have a dataset (shown below) that undergoes sorting by 'section'. Each item is placed into a UL based on its section when the page loads. My goal is to automatically update the section in the database when a user drags an item to a different s ...

Clicking on the ajax tab control in asp.net displays a single rectangular box - how can this be removed?

When using tab control in Ajax, I encountered an issue where a blue rectangle box appeared when clicking or opening the page. How can I remove this unwanted box? ...

What is the best way to iterate through results in a Realm custom resolver function when receiving a response from the

My goal is to develop a function for my custom resolver that retrieves all documents in a collection and updates the payload with new data. The code snippet below illustrates how I am currently getting one client and modifying its information: exports = (i ...

Visualizing a Dynamic Website Structure with PHP, Javascript, and JQuery

I am looking to develop an application that can generate a diagram displaying all the external links on my website. For example, showing that www.example.com/articles/some-title.html is linked to my homepage. Home - www.example.com/some-text - www.ano ...

Uploading Files with Angular and Including Extra Data in ASP.NET Web API

I am facing an issue while trying to upload a form containing text fields and a file to my WebAPI. Every time I attempt to upload, I encounter a 415 error and the ASP controller breakpoint does not get hit. Here is a snippet of my code: Angular Service / ...

Could you please show me a demonstration of how to add text animation dynamically to a Div element?

I am interested in creating a text animation using JQuery, but I am unsure of how to start and actually code it. Where should I begin or what can/should I search for on Google? If you take a look at , you will notice the moving text and the seamless way t ...

A comprehensive guide on creating a package that combines an href link with an <li> element

I am currently using the <li> tag to display href links. The issue I am facing is that when I click on the 'box,' it does not directly link to another page. Instead, I have to click on the href link for it to redirect to another page. Is th ...

nvim-typescript incorrectly flags non-existent type errors

I am experimenting with using neovim and have set up a minimal configuration as follows: call plug#begin() Plug 'mhartington/nvim-typescript', {'do': './install.sh'} Plug 'leafgarland/typescript-vim' Plug 'He ...

Using Google App Script for Slides to center-align text within a text box

Currently, I am tackling a project that demands the center alignment of text within a textbox on a google slide using a google app script. The primary objective is to fetch text from a google worksheet and an image from google drive. Subsequently, combine ...