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

There was an error encountered trying to access the options (URL) with a 405 method not allowed status. Additionally, the request to load the (URL) failed with a response indicating an

I attempted to retrieve data from an API using httpClient in Angular 5, but encountered errors. Below are the issues I faced: 1) ERROR: when trying to access http://localhost:8080/api/getdata, I received a 405 error (method not allowed). 2) ERROR: failed t ...

Learn how to deactivate the pause button with just one click and re-enable it once the popup appears using Angular2 and Typescript

Can anyone assist with solving an issue I am facing with a timer and a pause button? I need the pause button to be disabled once clicked, until a popup appears, then it should become enabled again. My code snippet is provided below: HTML: <button md-i ...

What are some creative ways to emphasize certain dates?

Is there a way to customize mui-x-date-pickers to highlight specific days from a Date array with green filled circles around them? I am using new Date and wondering how to achieve this effect. Below is the code snippet I am currently working with: <Dat ...

Getting access to a variable that was declared in a service class from a component in Angular 9 can be achieved by following

A problem has surfaced in my chat application where the local variable that I set to true in the service class after login is not being accessed correctly from another component. Despite changing it to true, the initial value of false is still being return ...

Can Schema and Model/Entity Files be Decoupled in TypeORM?

Having experience with PHP (Laravel/Eloquent, Symfony/Doctrine), I am accustomed to ORMs not defining schema but making schema attributes accessible. In my previous work, I never had to use a "Model" file to manage schema as it was always handled through m ...

Unlocking the Secrets of AnimatedInterpolation Values

I have a question about how to access the value of an AnimatedInterpolation in react-native without resorting to calling private code. To achieve this, I first create an animated value and then wrap it in an interpolation like so: animated = new Anima ...

Dynamic TypeScript class constructor argument typing determined by user input

I am working on creating a dynamic class that can adapt its argument properties based on a certain value. To illustrate this concept, let's consider a simple example: Imagine I have a class called Customizer, and depending on the value of the mode pr ...

Unable to access component properties through react-redux

Context: A React Native application utilizing Redux for managing complexity. Versions: typescript v3.0.3 react-native v0.56.0 redux v4.0.0 @types/react-redux v6.0.9 @types/redux v3.6.0 Issue: The main JSX component in my app is unable to access proper ...

Issue with Angular Provider Missing in Ahead-Of-Time Compilation

My goal is to simplify the declaration of a provider by using a static function in this way: const provider = MyModule.configureProvider(); @NgModule({ bootstrap: [AppComponent], declarations: [AppComponent], imports: [ ... ], providers: [ ...

Receiving distinct data from server with Ionic 2 promises

Utilizing ionic 2 RC0 with promises to retrieve data from the server, I am facing an issue where I consistently receive the same data in every request due to the nature of promises. Hence, my question is: How can I tackle this problem and ensure differen ...

Is it possible for Angular 2 JWT to have an unauthenticatedRedirector feature?

Having transitioned from Angular 1 where JWT tokens were used for user authentication, I had the following code: .config(function Config($httpProvider, jwtOptionsProvider) { // Interceptor to add token to every $http request jwtOptionsProv ...

Developing a function that takes a parameter which can be used with or without an additional argument when invoked

In my React application, I have a method that accepts a parameter for displaying a modal. const displayModal = (p:Result) => { setConfirm(true); if(p) { //check variable for truthy setSelectedRow(p); } ...

Once the user logs out, they have the ability to navigate back using the back button. What steps can be taken to address this

route.ts const appRoutes: Routes = [ { path: '', redirectTo: 'login', pathMatch: 'full' }, { path: 'login', component: LoginComponent }, { path: 'dashboard', canActiva ...

The collaboration feature in Angular is not functioning properly

In my application, I have two modules aside from the main module: - The Global.module, which contains shared modules; - The Pages.modules, which includes my pages. My goal is to make the modules in Global.module accessible to Pages.modules. However, I enc ...

The term 'string' is typically employed as a data type, yet in this instance it is being utilized as an actual value

Just started working with TypeScript and encountered an issue while trying to set the state. Encountered this error message: 'string' is a type and cannot be used as a value here. const state = reactive({ user: { uid: "", ...

Solidjs: Implementing a Map in createStore does not trigger updates upon changes

As a beginner in solidjs, I might have missed something important. In the code snippet below, I am trying to understand an issue: const [state, setState] = createStore({ items: new Map() }); // e.g. Map<number, string> In a component, suppose I want ...

Unable to pass parameters through the URL in Angular's POST request

Hey there! I'm currently facing an issue with passing a parameter in the POST method URL within an Angular service to construct a URL for fetching data from an API. However, when I try calling it in the component file, I keep getting an error response ...

*NgFor toggle visibility of specific item

Here is a snippet of HTML code that I'm working with: <!-- Toggle show hide --> <ng-container *ngFor="let plateValue of plateValues; let i=index"> <button (click)="toggle(plateValue)">{{i}}. {{ btnText }}</button> ...

Using Typescript, develop a function within an entity to verify the value of a property

In my Angular 7 app, I have an entity defined in my typescript file as follows: export class FeedbackType { id: number; name: String; } I am looking to create a function within this entity that checks the value of a property. For example: feedba ...

Can't decide between ngOnInit() and ngAfterContentInit()?

As a newcomer to Angular, I sometimes get confused about the ngOnInit() and ngAfterContentInit() lifecycle hooks. According to the official documentation: ngOnInit() : This hook is used to initialize the directive/component after Angular has displayed the ...