Traveling from one child route to another

I am encountering issues with route navigation between child routes, as I keep receiving "routes not found" errors. Despite trying multiple solutions like injecting and refreshing after child configuration, I still face difficulties in navigating to a specific route.

For example, when attempting to navigate from create.ts to account_view, it indicates that the route name does not exist. Upon inspecting all the routes listed in this.router within create.ts, only accounts_overview and accounts_create are displayed, but not the child routes of accounts_overview.

app.ts

import {inject} from 'aurelia-framework';
import {RouterConfiguration, Router} from 'aurelia-router';
import {HttpClient} from "aurelia-fetch-client";
import {AureliaConfiguration} from "aurelia-configuration";
import {Container} from 'aurelia-dependency-injection';
import {AuthorizeStep} from 'app/authorize-step';

export class App {
    private router: Router;

    configureRouter(config: RouterConfiguration, router: Router): void {
        config.title = 'Optios partners';
        config.addAuthorizeStep(AuthorizeStep);
        config.map([
            { route: '', redirect: "login" },
            { route: '/accounts', name: 'accounts', moduleId: 'account/view/index', title: 'Accounts', settings: { roles: [ 'partner', 'admin' ] } }
        ]);
        this.router = router;
    }
}

accounts/view/index.ts

import {computedFrom} from 'aurelia-framework';
import {RouterConfiguration, Router} from 'aurelia-router';

export class Index {
    router: Router;
    hasSearchFocus: boolean;
    search: string = '';

    configureRouter(config: RouterConfiguration, router: Router)
    {
        config.map([
            { route: '/overview', name: 'accounts_overview', moduleId: 'account/view/overview', nav: true },
            { route: '/create', name: 'accounts_create', moduleId: 'account/view/create', nav: true }
        ]);

        this.router = router;
        this.router.refreshNavigation();
    }
}

accounts/view/overview.ts

import {AccountRepository} from "../repository/account-repository";
import {inject, computedFrom} from 'aurelia-framework';
import {RouterConfiguration, Router} from 'aurelia-router';
import {EventAggregator} from 'aurelia-event-aggregator';

@inject(AccountRepository, EventAggregator)
export class Overview {
    router: Router;
    eventAggregator: EventAggregator;
    accountRepository: AccountRepository;
    accounts: string[];
    previousLetter: string = 'Z';

    configureRouter(config: RouterConfiguration, router: Router)
    {
        config.map([
            { route: ['', '/blank'], name: 'account_blank', moduleId: 'account/view/blank', nav: true },
            { route: '/:id', name: 'account_view', moduleId: 'account/view/view', nav: true, href: '0' }
        ]);

        this.router = router;
        this.router.refreshNavigation();
    }
}

accounts/view/create.ts

import {inject} from 'aurelia-framework';
import {Router} from 'aurelia-router';
import {computedFrom} from 'aurelia-framework';
import {HttpClient} from 'aurelia-fetch-client';
import {AccountRepository} from "../repository/account-repository";

@inject(AccountRepository, Router)
export class Create
{
    router: Router;
    accountRepository: AccountRepository;
    name: string;
    isSubmitted: boolean = false;

    constructor(accountRepository: AccountRepository, router: Router)
    {
        this.accountRepository = accountRepository;
        this.router            = router;
    }

    create()
    {
        this.isSubmitted = true;
        if (this.isValid()) {
            this.accountRepository
                .create(this.name)
                .then(response => {
                    if (! response.ok) {
                        throw Error(response.statusText);
                    }

                    return response.json();
                })
                .then(response => {
                    console.log(this.router.routes);
                    this.router.navigateToRoute('account_view');

                    return response;
                })
                .catch(error => {
                    console.error(error);
                });
        }
    }
}

Answer №1

Routing to a named route on a different Child Router is currently not supported in Aurelia. However, our team is actively exploring solutions for this issue in upcoming releases.

It appears that the structure of your child routers may be causing complications in achieving your desired outcome. Your current router hierarchy resembles:

     APP
      |
    ACCOUNTS
     /    \
  OVERVIEW CREATE

In order to facilitate navigation between the CREATE and OVERVIEW routers, consider simplifying the nesting of your routers. Additionally, utilizing the EventAggregator to broadcast events from the child router to the parent router could provide a workaround for your scenario.

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

retrieve the router information from a location other than the router-outlet

I have set up my layout as shown below. I would like to have my components (each being a separate route) displayed inside mat-card-content. The issue arises when I try to dynamically change mat-card-title, as it is not within the router-outlet and does not ...

having difficulties sorting a react table

This is the complete component code snippet: import { ColumnDef, flexRender, SortingState, useReactTable, getCoreRowModel, } from "@tanstack/react-table"; import { useIntersectionObserver } from "@/hooks"; import { Box, Fl ...

Tips for integrating the react-financial-charts library into your React and JavaScript project

While exploring the react-financial-charts library, I discovered that it is written in TypeScript (TS). Despite my lack of expertise in TypeScript, I am interested in using this library in my React+JS project due to its active contributions. However, I hav ...

Leveraging the power of TypeScript and Firebase with async/await for executing multiple

Currently, I am reading through user records in a file line by line. Each line represents a user record that I create if it doesn't already exist. It's possible for the same user record to be spread across multiple lines, so when I detect that it ...

Exploring disparities between the Client SDK and Admin SDK in conducting firestore queries

I am encountering difficulties with my query while running it in Firebase Functions. It functions perfectly on the client side, but fails to work in Functions. I am curious if there is a way to modify it to function with Admin SDK as well. Am I making any ...

Tips for handling numerous observables in Angular 7

I am working on an Angular 7 application that deals with a total of 20 sensor data. My goal is to receive data from a selected sensor every 5 seconds using observables. For example: var sensorId = ""; // dynamically chosen from the web interface var senso ...

Retrieve indexedDb quota storage data

I attempted the code below to retrieve indexedDb quota storage information navigator.webkitTemporaryStorage.queryUsageAndQuota ( function(usedBytes, grantedBytes) { console.log('we are using ', usedBytes, ' of ', grantedBytes, & ...

How can we avoid duplicating injectors in a child class when extending a class that already has injected services?

Delving deep into TypeScript inheritance, particularly in Angular 11, I've created a BasePageComponent to encompass all the necessary functions and services shared across pages. However, I've encountered an issue where my base class is becoming b ...

The formatting in vscode does not apply to .tsx files

For a while now, I've relied on the Prettier extension in Visual Studio Code for formatting my code. However, since switching to writing React with Typescript, I now need to configure Prettier to format .tsx files accordingly. ...

Error: Undefined object trying to access 'vibrate' property

Good day, I apologize for my poor English. I am encountering an issue with Ionic Capacitor while attempting to utilize the Vibration plugin. The documentation lacks detailed information, and when checking the Android Studio terminal, I found the following ...

How can I extend a third-party JavaScript library in TypeScript using a declaration file?

Currently, I am working on creating a .d.ts file for an external library called nodejs-driver. While I have been able to map functions and objects successfully, I am struggling with incorporating the "inherit from objects defined in the JS library" conce ...

Creating a custom autocomplete search using Angular's pipes and input

Trying to implement an autocomplete input feature for any field value, I decided to create a custom pipe for this purpose. One challenge I'm facing is how to connect the component displaying my JSON data with the component housing the autocomplete in ...

Tips for creating a test to choose a movie from the MuiAutocomplete-root interface

I am currently utilizing Material UI with React using Typescript and I am looking to create a test for the autocomplete functionality using Cypress. Here is the approach I have taken: Identifying the Autocomplete component and opening it, Choosing an opti ...

What benefits does Observable provide compared to a standard Array?

In my experience with Angular, I have utilized Observables in the state layer to manage and distribute app data across different components. I believed that by using observables, the data would automatically update in the template whenever it changed, elim ...

An error is thrown when a try/catch block is placed inside a closure

An issue arises when attempting to compile this simple try/catch block within a closure using TypeScript: type TryCatchFn = (args: any, context: any) => void; function try_catch(fn: TryCatchFn): TryCatchFn { return (args, context) => void { ...

Typescript custom sorting feature

Imagine I have an array products= [{ "Name":'xyz', 'ID': 1 }, { "Name":'abc', 'ID': 5 }, { "Name":'def', 'ID': 3 } ] sortOrder=[3,1,5] If I run the following code: sortOrder.forEach((item) =&g ...

What function is missing from the equation?

I am encountering an issue with an object of type "user" that is supposed to have a function called "getPermission()". While running my Angular 7 application, I am getting the error message "TypeError: this.user.getPermission is not a function". Here is w ...

TypeScript Generic Functions and Type Literals

Everything seems to be running smoothly: type fun = (uid: string) => string const abc: fun = value => value const efg = (callback:fun, value:string) =>callback(value) console.log(efg(abc, "123")) However, when we try to make it generic, we e ...

Error encountered during Typescript compilation: Type 'void' cannot be assigned to type 'Item[]'

Below are my typescript functions. When I edit in vscode, the second function does not show any error message. However, upon compilation, an error is displayed for the second function: error TS2322: Type 'Promise<void>' is not assignable t ...

Using TypeScript to return an empty promise with specified types

Here is my function signature: const getJobsForDate = async (selectedDate: string): Promise<Job[]> I retrieve the data from the database and return a promise. If the parameter selectedDate === "", I aim to return an empty Promise<Job[] ...