Unable to properly navigate from the parent route to the child route using navigateByUrl function

When attempting to navigate to a sub component in my app, I have encountered an issue.

this.router.navigateByUrl(this.rightsService.pathToRedirectTo).then((data) => {
  console.log(data)
});

The navigation works perfectly fine when passing /mainRoute in the routing setup:

{ path: 'mainRoute', loadChildren: () => import('./xxx/xxxx').then(m => m.xxxModule) }, 

However, it fails to redirect ( data = false ) when passing /mainRoute/subRoute/1

The subRoute routing definition looks like this:

{ path: 'subRoute/:id', canActivate: [ViewGuard], component: ViewComponent },

I am unsure why the second case is not working as expected.

This is how my parent routing structure is set up:

{ path: 'login', component: LoginComponent },
{ path: 'mainRoute', loadChildren: () => import('./main/main.module').then(m => m.mainModule) },
{ path: '**', redirectTo: 'login' }];

Within the mainModule, the routing configuration includes:

{ path: 'subRoute/:id', canActivate: [ViewGuard], component: ViewComponent },
{ path: 'subroute/:id/childRoute/:sId', canActivate: [SViewGuard], component: SiewComponent }];

Answer №1

Could you please verify what value is being returned by your ViewGuard when attempting to redirect to /mainRoute/subRoute/1? It appears that the route guard may be returning false, which could potentially be causing this issue. Additionally, if there are any interceptors being used for this route or its parent components, it would be beneficial to check the values that these interceptors are returning as well.

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

Show or hide comment sections using jQuery on a single webpage

Currently, I have implemented a script to toggle the visibility of comments on several WordPress-based websites. The script works well on most sites, but I am facing an issue with a site using the Hero theme. On the index pages, the theme displays content ...

Menu Navigation: Sequentially Colored Badges for Navigation Items

Within the MainService.ts file, there is a function that can alter the color set in badgesColorSet. The json config already defines 3 colors and the goal is for these colors to change each time the website is refreshed - for example, changing from red to g ...

Can you include the dollar symbol in the currency format?

I currently have this code that formats numbers into currency format, however I would like to include the dollar sign ($) before the numbers. document.getElementById("numbers").onblur = function (){ this.value = parseFloat(this.value.r ...

Exploring font metrics for NSAttributedString using JavaScript in Automation

In macOS Sierra JavaScript for Automation, we can use the following code snippet to retrieve metrics for a specific string in the default Helvetica 12 font: // helvetica12Width :: String -> Num function helvetica12Width(str) { return $.NSAttributed ...

Is it possible to utilize PHP to dynamically add a URL, media, and description on Pinterest?

Check out this code snippet: <script type="text/javascript"> (function() { window.PinIt = window.PinIt || { loaded:false }; if (window.PinIt.loaded) return; window.PinIt.loaded = true; function async_load(){ var s = document.createElement("scrip ...

The method of applying conditional formatting to an HTML table is dependent on the specific

I've come across some code that I want to tweak: conditional formatting of html table cells In my project, there are two different sets of formatting rules for a final table with 37 columns. Most of the columns will follow rule 1, while about 10 of ...

Unable to retrieve the information from URL.createObjectURL

I'm interested in learning how to retrieve the data wrapped in URL.createObjectURL. So, I decided to write the following code snippet. function convertTypedArrayToURL(typedArray, mimeType) { return URL.createObjectURL(new Blob([typedArray.buffer], ...

Troubleshooting vague errors with uploading large files in Golang's net/http protocol

I've encountered a challenging error while uploading large files to a server built with Golang's default net/http package. The upload process is defined as follows: uploadForm.onsubmit = () => { const formData = new FormData(uploa ...

When using a custom AJAX function, make sure that bindings are functioning properly when setting properties within a callback in Ember

I've encountered some unexpected behavior while trying to set an Ember property inside a custom AJAX function callback. The AJAX function is triggered in the route, as seen in the code snippet below. The success callback updates the 'session.aja ...

An error has occurred in the tipo-struttura component file in an Angular application connected with a Spring backend and SQL database. The error message indicates that there is a TypeError where the

Working on my project that combines Spring, Angular, and MYSQL, I encountered a challenge of managing three interconnected lists. The third list depends on the second one, which in turn relies on user choices made from the first list. While attempting to l ...

Launch a new pop-up window with a designated keyboard language

My JavaScript code opens a new window using this syntax: window.open(URL); However, I've noticed that even when the browser's keyboard language is set to 'fa' during opening, the new window still defaults to 'en'. Is there ...

The code functions correctly when retrieving information from a file, however, encounters issues when retrieving data

While working on my React application, I encountered a situation where I needed to read the value for translation from a file stored in the public folder. The files were saved at https://i.sstatic.net/oWXCh.png However, due to the dynamic nature of our d ...

Issue with source file detection in RequireJS and Karma

Having trouble testing my Angular scripts with Karma and RequireJS, as I keep encountering this error: Error in Firefox 28.0.0 (Mac OS X 10.9): 'There is no timestamp for /base/app/public/js/test/unit/controllersSpec.js!' Warning [web-server]: ...

Issue with displaying YouTube videos in HTML causing them to be downloaded instead of playing

I'm currently facing an issue with loading a video on my HTML page using the following code: <video v-for="(data, key) in projectData.videos" :key="key" width="320" height="240" controls> <source :src="data.url"> </video> One ...

Remembering position in JSP using Java Beans

In my "Web Engineering" assignment, I am tasked with developing a Web Application game using JSP, Servlets, and Java Beans. The game mechanics are already in place with the Servlet controlling the algorithms, JSP handling the Model/View, and Beans managing ...

Encountering Uncaught Promise Rejection Warning in Node.js

I can't figure out why I am receiving this error or warning when my code appears to be correct. Below is a snippet of the UserModel that I have been working on: const fs = require('fs'); class UserModel { constructor(filename) { ...

Exploring support classes in an Angular application

Within my Angular project, I have not only component classes but also auxiliary classes for data model representation and data iterators. When Angular generates test classes for components, they are named in the format component-name.component.spec.ts I ...

Issue: The function is attempting to use the React Hook "useState" inappropriately

After updating the navbar on my NextJs site and making changes to the header, I encountered a build error that I couldn't resolve. The error message can be seen here: https://i.sstatic.net/jjXJG.png I tried researching and tweaking the code, especial ...

Enhancing view with Typescript progressions

My current view only displays a loader.gif and a message to the user. I am looking to enhance the user experience by adding a progress indicator, such as "Processing 1 of 50", during the data update process. The ts class interacts with a data service layer ...

Tips on storing base64-encoded PDF files in a database using a URL?

Currently, I am working on generating a PDF of an HTML table. My goal is to save the generated PDF in a database. The current script allows for downloading the PDF, but I want to modify it so that the PDF file is sent to the controller side and then saved ...