Establishing the default nested state in ui-router

I am facing an issue with two level nested states on ui-router where I cannot set a default nested state for a specific view.

The challenge is to load the state cars.detail.supply.list when the state cars.detail is active without changing the current URL.

The desired outcome is to display the list of supplies without having to click on the List supplies button.

What could be causing this problem?

Complete Code: https://plnkr.co/edit/DqwhaDXh3biMbq9PLCV3?p=preview

ui-states:

.state('cars.detail', {
    parent: 'cars',
    url: '/edit/:id',
    views: {
        'content@index': {
            templateUrl: 'cars.detail.html',
            controller: 'CarDetailController'
        },
        'supplies': {
            templateUrl: 'cars.supply.html',
            controller: 'CarDetailController'
        }
    }
})

.state('cars.detail.supply', {
    url: '',
    parent: 'cars.detail',
    abstract: true,
    //'default': '.list',
    views: {
        '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6e1d1b1e1e02070b1d2e0d0f1c1d400a0b1a0f0702">[email protected]</a>': {
            templateUrl: 'cars.supply.html',
            //controller: 'SupplyListController'
        }
    }
})
.state('cars.detail.supply.list', {
    parent: 'cars.detail.supply',
    url: '',
    views: {
        '@cars.detail.supply': {
            templateUrl: 'cars.supply.list.html',
            controller: 'SupplyListController'
        }
    }
})
.state('cars.detail.supply.add', {
    parent: 'cars.detail.supply',
    url: '/add-supply',
    views: {
        '@cars.detail.supply': {
            templateUrl: 'cars.supply.add.html',
            controller: 'AddSupplyController'
        }
    }    
})

The view:

<div>
    ...

    <h4 ng-if="car.id">
        Supplies

        <a class="btn btn-default btn-sm pull-right" ui-sref="cars.detail.supply.add({ carId: car.id })">
            <i class="glyphicon glyphicon-plus"></i> Add supply
        </a>

        <a class="btn btn-default btn-sm pull-right" ui-sref="cars.detail.supply.list({ carId: car.id })">
            <i class="glyphicon glyphicon-plus"></i> List supplies
        </a>
    </h4>
    <div ui-view="supplies" class="">
    </div>
</div>

Approaches attempted:

Answer №1

To successfully activate it, you must distinguish between the URLs of cars.detail and cars.detail.supply.list. The first step is to assign a URL to cars.detail.supply.list:

.state('cars.detail.supply.list', {
    parent: 'cars.detail.supply',
    url: '/list',
    templateUrl: 'cars.supply.list.html',
    controller: 'SupplyListController'
})

Once the state URLs are distinct, you can transition to the list state by updating the link in the car list repeater with:

ui-sref="cars.detail.supply.list(...)"

Alternatively, you can specify a redirection from the details state to the details's list state in app.js:

$urlRouterProvider.when('/dashboard/cars/edit/{id}', '/dashboard/cars/edit/{id}/list');

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

Invoking functions with JavaScript objects

Can anyone help me figure out what is wrong with the following JavaScript code? <form> What is 5 + 5?: <input type ="number" id ="num_answer;"/> </form> <script> function basic_math(){ var num_val = document.getElem ...

Console error due to misconfiguration of AngularJS checkbox option

My requirements are twofold: Only one of two boxes can be selected at a time. The name of the selected box must be captured. Although when I print out the list of checkbox objects they appear to be correct, checking in the console reveals otherwise. For ...

Utilizing Spaces in Parameters for discord.js

My current challenge involves sending tweets from discord.js. However, I encountered an issue where messages with spaces are being posted as "hello,from,discord" instead of "hello from discord". Can anyone help me rectify this? const Twitter = require(&apo ...

Having trouble retrieving the updated useState variable outside of useEffect in React Hooks?

Recently, I dove into the world of React and started developing a React app that allows users to drag food items to an order list using React DND. However, I encountered a problem where I couldn't access the updated OrderList variable outside the useE ...

Is there a way to verify the presence of an email, mobile number, and Aadhar number in my MongoDB database?

const express = require('express'); const router = express.Router(); require('../db/conn'); const User = require('../model/userSchema'); router.get('/', (req, res) => { res.send(`Greetings from the server vi ...

Issue with Jquery checkbox calculator constantly displaying Not a Number (NaN)

I'm facing an issue with jQuery. The Custom Wpform Checkbox Field is returning NaN. HTML <div class="wpforms-payment-total"> $ 85 </div> <input type="checkbox" name="myBox2" size="1 ...

Query to retrieve the most recent message from all users and a specific user resulting in an empty array

My goal is to retrieve all messages exchanged between User A and any other user. This is my schema structure: const MostRecentMessageSchema = new Schema({ to: { type: mongoose.Schema.Types.ObjectId, ref: "user" }, from: { type: mongoose ...

A guide to creating an or statement in MongoDB using the find method in Mongoose

I'm seeking a solution to check for bookings within a specified time range in MongoDB using Mongoose. I am unsure of how to incorporate the OR condition into my query. Below is the current code snippet: const appoinments = await Appointment.find({ ...

Surprising Regex Match of ^ and special character

My regular expression is designed to break down calculator input strings, such as 12+3.4x5, into individual tokens like 12, +, 3.4, x, and 5 Here is the regular expression I am using: \d+\.?\d+|[\+-÷x] However, I am encountering une ...

Angular causing a database problem within MEAN stack

I recently encountered an issue where adding an item to my database only resulted in the ID being added, while the name attribute I specified for the item was not saved. This means that the 'name' attribute I assign to the 'player' enti ...

The `finally` function in promises is failing to execute properly

Currently working with Typescript and I've included import 'promise.prototype.finally' at the beginning of my index.js file (in fact, I've added it in multiple places). Whenever I try to use a promise, I encounter the error message say ...

Combining items from the identical array in pairs using distinct identifiers

I have an array containing double values. const data = [ -0.003,-8.178509172818559E-16, 0.002,-1.3576469946421737E-15, 0.007,-1.2329107629591376E-1] I am looking to utilize these values in react-vis. The necessary syntax for data insertion in react-vis ...

Angular method $http.get is failing to function as intended

This is the HTML and JavaScript code I have written. <!DOCTYPE html> <html ng-app> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title></title> <meta name ...

Exploring Angular 10: Managing Two Promises in ngOnInit

I am currently working on integrating the Strava API into my Angular app. To summarize briefly: When a user clicks on a button to connect to Strava They are redirected to Strava for authentication (using PKCE) Strava then redirects back to my app with a ...

Unauthenticated user attempting to send a post request via React JS without proper authentication

Currently, I am working on a project where I am following a video tutorial that demonstrates how to authenticate a user using node and passport JS. The tutorial itself uses Hogan JS as its view engine, but I have decided to implement React as my front end ...

ng-flow configuring CSRF token in request header

When utilizing file uploads with flow.js, I encountered a problem setting the X-XSRF-TOKEN header. Since flow.js does not utilize the $http resource to post files, I had to explicitly set the header myself. Here is what I did: profile.edit.html: <di ...

Issue: ArrayBuffer failing to function properly in conjunction with Float64Array in NodeJS

Having some trouble with getting a Float64Array to work with an array buffer in Node. Here's what I've tried... var ab = new ArrayBuffer(buffer.length); var view = new Uint8Array(ab); console.log(view.length);//prints 3204 However, when I try ...

What is the best way to divide two ranges that are intersecting?

Seeking a method to divide two overlapping ranges when they intersect. This is my current progress using typescript, type Range = { start: number; end: number; }; function splitOverlap(a: Range, b: Range): Range[][] { let result = []; const inters ...

Troubleshooting issue with Onchange in select HTML element within Django

I'm working with a Problems model in my project. In my Models file models.py class Problems(models.Model): Easy = 'Easy' Medium = 'Medium' Hard = 'Hard' NA = 'NA' DIFFICULTY = [ (NA ...

Tips for avoiding image flickering when refreshing the URI in a React Native app

How can I prevent unwanted flickering when a new image src is being loaded as a socket response that reloads multiple times in a second? ...