Navigational menu routing with AngularJS2 using router link paths

Currently, I am working on developing a navigation menu using angularJS2. Here is the snippet from my app.component.ts:

 import {provide, Component} from 'angular2/core';
    import {APP_BASE_HREF, ROUTER_DIRECTIVES, ROUTER_PROVIDERS, HashLocationStrategy, LocationStrategy, RouteConfig} from 'angular2/router';
    import {bootstrap} from 'angular2/platform/browser';
    import {Router} from 'angular2/router';


// Terrestrial
@Component({
    selector: 'terrestrial',
    template: '/terrestrial.html', // FUNCTIONAL
})
export class TerrestrialComponent { }


// Aerial Component
@Component({
    selector: 'aerial',
    templateUrl: '/aerial.html' --> NOT WORKING
})
export class AerialComponent { }


// Aquatic Component
@Component({
    selector: 'aquatic',
    template: 'aquatic.html' // FUNCTIONAL
})
export class AquaticComponent { }

@Component({
    selector: 'my-app',
    directives: [ROUTER_DIRECTIVES], 

    template: `    
    <nav>
      <ul>
              <li><a [routerLink]="['/Aerial']">AERIAL</a></li>
              <li><a [routerLink]="['/Aquatic']">AQUATIC</a></li>
              <li><a [routerLink]="['/Terrestrial']">TERRESTRIAL</a></li>
      </ul>
    </nav>
    <router-outlet></router-outlet>
    `,  
})

@RouteConfig([
    { path: '/aerial', component: AerialComponent, as: 'Aerial' },
    { path: '/aquatic', component: AquaticComponent, as: 'Aquatic' },
    { path: '/terrestrial', component: TerrestrialComponent, as: 'Terrestrial' }
])

export class AppComponent {}

This is how my file structure looks:

-DEV 
   - app.component.ts
   - boot.ts
   - terrestrial.html
   - aerial.html
   - aquatic.html

While I can successfully navigate to "aquatic" and "terrestrial", I'm having trouble navigating to "aerial" which is defined in "templateURL". See below for what I have attempted:

templateUrl: './aerial.html' --> NOT WORKING
templateUrl: 'aerial.html' --> NOT WORKING

Answer №1

Here are a few things to consider:

template: '/terrestri.html', // How does this work?

Template is intended for inline HTML like this:

template: `<div></div>`

You may be getting output like: /terrestri.html

Where is your app located? If it is in the app directory, then your templateUrl should be:

templateUrl: '/app/volatili.html'

In your example, is DEV the parent directory? Try using:

templateUrl: '/DEV/volatili.html'

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

Tips for sorting/merging/consolidating data in Angular

Take a look at this code snippet: rowData = [ [ '2019-12-10 08:00:00', '2019-12-10 08:00:00', '2019-12-10 08:00:00', '2019-12-10 08:00:00', '2019-12-10 08:00:00', '2018-12-10 08:00:00' ...

How can the component prefix be replaced or updated in Angular 8/9?

Is there a way to efficiently replace or modify the outdated component prefix all at once? OR How can I create a dynamic prefix system that automatically updates all component prefixes whenever changes are needed? ...

What could be causing my vis.js network's node hover popups to not function properly?

I've encountered an issue where, despite adding the 'title' property to my node objects, the pop up window with the title content doesn't appear when I hover over a node. Here are the options I've chosen and how I've set up m ...

I am encountering an "ERROR null" message in my Angular application within VSCode. How can I identify the root cause of this issue?

After compiling my Angular v17 project, I encountered error messages in the terminal that do not provide any specific reference or link to the issue. Surprisingly, the web browser console does not display any errors either. How should I proceed to identi ...

Determine the chosen selection in an Angular Material autocomplete feature

Is there a method to determine which option is currently selected in the autocomplete feature so that when the user hits tab, I can automatically choose that option instead of changing the focus of the field. Check out my code snippet below: <div clas ...

Deactivate multiple textareas within a loop by utilizing JQuery/Typescript and KnockoutJS

I am working on a for loop that generates a series of textareas with unique ids using KO data-binding, but they all share the same name. My goal is to utilize Jquery to determine if all the textareas in the list are empty. If they are, I want to disable al ...

What is the best way to refine React Component's props with Typescript?

My setup involves utilizing two specific components: Test and Subtest. The main functionality of the Test component is to provide visual enhancements and pass a portion of its props down to the Subtest component. Some props in the Subtest component are des ...

Is it possible to customize the default typography settings for Textfields and other components using a theme in Material UI v5?

Is there a method to customize the default typography for TextField and all inputs using themes? I am aware of this approach: components: { MuiInput: { styleOverrides: { root: { fontSize: '16px', ...

A guide on simulating x-date-pickers from mui using jest

I have successfully integrated a DateTimePicker into my application, but I am facing an issue with mocking it in my Jest tests. Whenever I try to mock the picker, I encounter the following error: Test suite failed to run TypeError: (0 , _material.gen ...

Can you advise on how to generate a key to access an environment.ts value within a *ngFor loop? Specifically, I am trying to locate keys that follow the pattern 'environment.{{region}}_couche_url' within the loop

I currently have a block of HTML code that is repeated multiple times. <!-- Metropolitan Map --> <div> <app-map [name] = "(( environment.metropole_name ))" [layer_url] = "(( environment.metropole_layer_url ))" ...

What exactly is the function of the NextPage feature in Next.js?

Recently, I began incorporating TypeScript into my Next project. Could someone clarify the purpose of the following code snippets for me? import { NextPage } from 'next'; export const Page: NextPage = () => {} After reviewing the documentation ...

Errors encountered when using TypeScript with destructured variables and props not being recognized

I have a function that returns data. The object is structured with properties such as headerMenu, page, content, and footer. These properties are defined in DataProps interface. When I try to destructure the data object using the line: const { headerMenu, ...

Angulating Service Testing

I am encountering an issue that I'm not sure how to resolve because I am inexperienced when it comes to testing. Currently, I am testing a service that includes the following code: import { Injectable } from '@angular/core'; import { Endpo ...

In search of assistance with resolving a React Typescript coding issue

I need help converting a non-TypeScript React component to use TypeScript. When attempting this conversion, I encountered the following error: Class 'Component' defines instance member function 'componentWillMount', but ext ...

Efficient method to access two arrays simultaneously and combine them into an associative array in JavaScript

When using Ajax to return a table, you have the option of separating column names and row values. Here are two ways to do it: let columns = ["col1", "col2", "col3"]; let rows = [ ["row 1 col 1", "row 1 col 2", "row 1 col 3"] , ["row 2 col 1", "r ...

Is it feasible to integrate gMaps with Angular2? How can I go about accomplishing this task?

In developing a typeahead service for cities and similar functions, I require the use of a typeahead directive (ng2-bootstrap) with an array of strings provided by the service. Google Maps is my chosen solution for this task. Below is code extracted from ...

Incorporating Bootstrap 3 into an Angular 2 Application with Webpack

My Angular 2 project is utilizing the Webpack module bundler and I am looking to incorporate Bootstrap into the application using webpack. Bootstrap has been installed via npm, as reflected in my package.json file: "devDependencies": { "@angular/co ...

I'm currently utilizing CSS GRID to create a map layout, but I'm encountering an issue where the layout is not filling the entire screen. I'm wondering how I can achieve this in Angular

Here is the unique html code snippet for a layout that dynamically creates grids using json input: <!DOCTYPE html> <html lang="en"> <head> <title>Booking Page</title> </head> <body> <div ...

What is the best way to create Jest unit tests for an Angular Component without using TestBed?

I'm diving into the world of Jest testing and feeling lost as to why my tests keep failing. If you have any recommendations for videos or articles that focus on writing Jest unit tests for Angular components and services without using "TestBed," plea ...

What to do in Angular2 when two 'root' elements are required?

I've taken on the challenge of teaching myself angular2 and am currently working on a basic app that follows a common website layout: Header for items like search and logo, and main body for content. My current dilemma is this: Take Facebook as an ex ...