Conflicting abstract views in UI-Router routes

I'm currently using UI-Router and trying to incorporate a subview into another view. Specifically, I want to display the "owner" view within the "dog" view. The following code accomplishes this:

Here is how my UI-Router configuration looks like:

.state('dogAbstract', {
    url: '/dog/:dogId',
    abstract: true,
    templateUrl: 'client/dogs/views/dog.ng.html',
    controller: 'dogCtrl',
})
.state('dog', {
    url: "",
    parent: "dogAbstract",
    views: {
        "owner": {
            templateUrl: 'client/owners/views/owner.ng.html',
            controller: 'ownerCtrl'
        }
    }
})
.state('dogsList', {
    url: '/dogs',
    templateUrl: 'client/moves/views/dogs-list.ng.html',
    controller: 'dogsListCtrl',
})

The issue I am facing is with the current URL structure which is not ideal. To access a specific "dog," users need to navigate to /dog/dogId. However, I believe it would be more in line with REST principles if the URL was /dogs/dogId. The problem arises when I try changing the URL of 'dogAbstract' to /dogs as it conflicts with the existing "dogsList" page. It seems that I can only have one or the other.

Is there a way to configure the URLs so that I can have the list at /dogs and view an individual dog at /dogs/dogId? Any insights would be greatly appreciated.

Answer №1

Visit this functional plunker

The key is to modify the sequence of definitions:

Start with the less specific URL and end with the most detailed one

UI-Router assigns priority based on the order of state declaration. The first match takes precedence:

// /dogs will be matched by this state
.state('dogsList', {
  url: '/dogs',
  ...
})

// Only URLs like /dogs/:dogId will match this state
.state('dogAbstract', {
  url: '/dogs/:dogId',
  ...
})

See it in action here

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

Ways to determine whether one side of a selected div is not obstructed by other divs

I am working with some div elements that are all sized 100x100px: Below is the HTML code for the 3 blocks: <div id="plane"> <div class="tile tile3" block-id="1" style-id="3" style="left:50px; top:50px"></div> <div class="tile t ...

Difficulty in modifying a global variable within an event handler

I am working on an ionic4 app that includes a button. The goal is to display the accelerometer alpha value when the button is pressed. However, I am encountering an issue where the event handler invoked by the event listener does not seem to update the g ...

The URL dynamically updates as the Angular application loads on GitHub Pages

Encountering an unusual issue when trying to access my angular website on GitHub pages. The URL unexpectedly changes upon opening the page. Please check it out at this link: The original expected URL should be However, as the page loads, the URL gets alt ...

Online application for saving a vast quantity of information on the user's device

Is there a way for a web application to store an extensive amount of data client-side, allowing for millions of records to be accessed offline by users exclusively on Chrome? I initially considered indexedDb, but I discovered it becomes almost unusable wi ...

Unable to see or play local mp4 file in Ionic iOS application

I am facing an issue with my Ionic app where I am trying to show a video playing in the background. The Jaeger25 HTMLVideo plugin works perfectly for Android, but when it comes to iOS, the video simply refuses to play. The video file is located in the www/ ...

Building with bricks and mortar does not involve organizing visual content

I'm currently trying to organize some fairly large images using masonry, but the code below doesn't seem to be working. I'm using node.js with express and have installed the masonryjs package in an attempt to make it work, but that approach ...

Learning how to use Express.js to post and showcase comments in an HTML page with the help of Sqlite and Mustache templates

I am facing a persistent issue while trying to post new comments to the HTML in my forum app. Despite receiving various suggestions, I have been struggling to find a solution for quite some time now. Within the comments table, each comment includes attrib ...

The range filter is exclusive to the initial controller

My range filter (see code below) is only working on my first controller. I have added the same filter to other controllers in the app.js and HTML, but it's not functioning for some reason. I checked the console for errors, but there are none. Here i ...

The CSS star rating system is malfunctioning

I'm struggling to implement a rating star system in my project. I have experimented with various code snippets, but none seem to be functioning properly. Take a look at the outcome: https://i.sstatic.net/g3DvH.png ...

Guide to dynamically loading customer data into an HTML table using JavaScript

I'm looking to populate a table with data on customers including their name, customer ID, and rental cost. Can anyone help me with the JavaScript code needed to insert this data into rows of the table? Your assistance is greatly appreciated. Below is ...

When communicating with the backend in a React application, the data is not being successfully sent using axios. An error message stating "Unsupported protocol

My current setup involves using Express.js as the backend and setting up a proxy to the backend in the package.json file of my React.js project. Initially, I encountered an error when using the fetch method, so I switched to using Axios to resolve this iss ...

The Bootstrap tooltip fails to display the visual style of the tooltip, only showing the data

Following the Bootstrap documentation for tooltips, I have tried to make the tooltip function work properly. However, when I hover over the text, the tooltip text Some tooltip text! only shows up with the alt="" function, but not styled as described in the ...

Encountering an unexpected token error while attempting to incorporate JQuery into a React JS project

I am currently diving into the world of React.js and attempting to incorporate a side navigation bar on my homepage. However, I encountered an eslint error when trying to implement the sidebar using jQuery code. Below you will find the code snippet for the ...

Guide on how to dynamically display a specific field in Material Table React

Hey there! I'm currently working with Material Table in React and I have a question. I want to generate a label tag for every cell, so I tried the following: <Table onChangePage={handleChangePage} page={p ...

CSS - owl carousel automatically stretches images to full width

Here is the code snippet that I am working with: $(document).ready(function() { $('.owl-carousel').owlCarousel({ loop:true, items:4, autoplay:true, autoplayTimeout:2000, autoplayHoverPause:true }); }); #owl-demo ...

Button for searching through the Bootstrap navigation bar

I'm currently working on adding a search menu to the navbar in two different designs - one for screens below 767px and another for screens above 767px. Although I have been successful in expanding the search bar, I am facing issues with the correct p ...

Using socket.io-client in Angular 4: A Step-by-Step Guide

I am attempting to establish a connection between my server side, which is PHP Laravel with Echo WebSocket, and Angular 4. I have attempted to use both ng2-socket-io via npm and laravel-echo via npm, but unfortunately neither were successful. If anyone h ...

Using CSS height 100% does not function properly when the content overflows

Here's what's going on with this code snippet: HTML <div class="one"> <div class="will-overflow"> </div> </div> CSS html, body { width: 100%; height: 100%; } .one { height: 100%; background: r ...

Utilizing Jade template helpers in both Node.js and the browser

When working with Jade templates in both an Express app and a browser environment, I find myself needing to format data before inserting it into inputs. Is it recommended to extend locals with similar functions in both Node.js and the browser? { formatDa ...

Continuously providing service within the application

In the process of developing my app, I have implemented a feature that sends the user's geolocation data to the server (given proper permissions). Currently, this geolocation data is only pushed to the server when the user navigates to the account pag ...