Unable to access default route

My application is structured as follows:

app.module.ts

    const routes: Routes = [
      { path: '', loadChildren: './modules/main/main.module#MainModule' },
    ];

    @NgModule({
      declarations: [
        AppComponent,
      ],
      imports: [
        RouterModule.forRoot(routes),
      ],
      providers: [
        AuthService,
        UtilService,
        UserService
      ],
      bootstrap: [AppComponent]
    })

    export class AppModule {
    }

main.module.ts

    @NgModule({
      declarations: [
        PressComponent,
        LegalComponent
      ],
      providers: [
        AuthService
      ],
      imports: [
        HomeModule,
        MainRoutingModule,
      ]
    })

    export class MainModule {
    }

main.routing.component.ts

const routes: Routes = [
  { path: '', component: HomeComponent, canActivate: [AnonymousGuard] },
  { path: 'home', component: HomeComponent, canActivate: [AnonymousGuard] },
  { path: '**', redirectTo: '', pathMatch: 'full' }
];

@NgModule({
  imports: [RouterModule.forChild(routes)],
  exports: [RouterModule]
})
export class MainRoutingModule implements OnInit {
  constructor() { }

  ngOnInit() {
    RouterModule.forRoot(routes, { scrollPositionRestoration: 'enabled' });
  }
}

When trying to access /home it works fine, but accessing / doesn't. How can I resolve this issue?

Answer №1

Did you remember to include the base href in your index.html file?

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

What is the process for configuring the directive to establish a drag-and-drop area within Angular?

I am currently working on implementing a file drag and drop zone in Angular. I have created the dropzone.directive and added it to the declarations in app.module.ts. While my code compiles and launches successfully, I am facing an issue where the HTML doe ...

What steps should I take in order to correctly implement the onChange event and retrieve the event.target.value in my

Incorporating useForm, yupResolver, and Yup for validation caused issues with the previously functioning handleChange function. The value variable doesn't log anything when console.logged, indicating a disconnect with the input field content. Addition ...

We encountered a surprising character "EOF" in the code. Could it be due to an unescaped "{" in the template? Please use "{{ '{' }}" to properly escape it

I encountered an issue while upgrading my angular 2 app from beta 9 to RC5. The error I received is in my form template. Below is the detailed error: zone.js:461 Unhandled Promise rejection: Template parse errors: Unexpected character "EOF" (D ...

The error message "Unable to find 'encoding'" in NextJS is triggered by the use of try/require in the node_modules folder

Running a NextJS app in typescript with version 13.4.19, utilizing @apollo/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0d7e687f7b687f4d392334233e">[email protected]</a> triggers a warning during the build proce ...

Setting up Electron with React and TypeScript: A Comprehensive Guide

I've been developing an app using Electron, React (jsx), and Babel. However, I recently made the switch to TypeScript and I'm struggling to get everything functioning properly. The npm packages I've tried only work for either React or TypeSc ...

Edit CSS attributes within Angular 2+ framework

When using jQuery, we have the ability to do the following: JQuery('.someStyle') .css({"background", "red"}) This allows us to directly change the CSS property in style. While working with Angular 2+, we can use [style.<property>] for ...

Angular2 display user's activity status on every individual page

How can I implement visitor status tracking for every page in angular2? I have a jwt based authentication system in place that is working correctly, but now I need to ensure that the visitor's login status is checked on each route. Here is an example ...

Employing 'as' in a similar manner to *ngIf

Utilizing the *ngIf directive, one can simplify code by assigning a property from an observable using syntax like *ngIf = (value$ | async).property as prop . This allows for the use of prop throughout the code without repeated references to (value$ | async ...

Challenges in implementing Angular's guard correctly

I have a simple task that I'm struggling with - creating a guard to protect a route from all users except those with an "admin" role. To check this, I send a request to my API server with the user's API token. The server then responds with eithe ...

Issue with intrinsic attributes detected in Typescript for the component

Hey, I'm encountering an issue that says, "The type '{ data: dataProp[]; }' cannot be assigned to type 'IntrinsicAttributes & dataProp'. A property 'data' does not exist on type 'IntrinsicAttributes & dataPro ...

Guide to sending a request to a third-party API using Node.js and Express.js with the 'Authorization: Basic' header

Attempting to utilize the UDEMY API, each request necessitates the inclusion of Authorization: Basic + keys header. The API documentation specifies: curl --user {YOUR_CLIENT_ID}:{YOUR_CLIENT_SECRET} https://www.udemy.com/api-2.0/courses/ curl -H "Au ...

Regular expressions that identify text located at the conclusion of a URL

Although the title may not be entirely appropriate, my goal is to create a regex that will remove any trailing '/' at the end of a URL under certain conditions. For example: http://stackoverflow.com/questions/ask/ to http://stackoverflow.com/qu ...

Having difficulty properly streaming UI components with Vercel's AI-SDK

Recently, I've been diving into the new Vercel's AI-SDK to expand my skills. My current project involves developing a persona generator that takes specific guidelines as inputs and generates persona attributes according to a given Zod schema. B ...

Steps to successfully deploy an Angular application using Jenkins

I'm in the process of deploying my Angular application to an AWS EC2 instance. For version control, I'm utilizing Bitbucket and Jenkins for continuous integration. ...

Integrating a third-party plugin into an Angular 4 component

I am interested in integrating a 3rd party plugin into a component, such as CKEDITOR or even a jQuery plugin. While I am aware of the ng-ckeditor package, I prefer not to use it because I want the flexibility to incorporate any plugin in the future withou ...

Organizing code with modules or namespaces in TypeScript

In a library-based project, I am aiming to have all classes accessible under a specific namespace. I seem to be overlooking a key step in organizing all classes within a namespace. Let's say I have two classes in two separate folders. The initial s ...

How to Apply a CSS Class to the Body Tag in Angular 2.x

How can I add [class.fixed]="isFixed" to the body tag when Angular 2.x is bootstrapped inside the body (outside my-app)? <html> <head> </head> <body [class.fixed]="isFixed"> <my-app>Loading...</my-app> </body> & ...

Is Angular's forkJoin being phased out?

Upon opening my Angular project today, I came across a warning message that said: The utilization of forkJoin is marked as deprecated: resultSelector is deprecated, it is recommended to use pipe to map instead (deprecation) https://i.sstatic.net/vFpeu.pn ...

Upgrade the map function from rxjs5 to rxjs6

I need help transitioning this code from rxjs5 to rxjs6: return this.http.put(url, image, options).map((res, err) => { return res; }).catch(err => { if (err.error instanceof Error) { return err.error; } else { t ...

Make sure PTable maintains a horizontal layout on any device with PrimeNG

When I view my Ptable on desktop or iPad, it looks like this: https://i.stack.imgur.com/ONqZV.png However, when I switch to a device like an iPhone X, it changes to this layout: https://i.stack.imgur.com/H2q7j.png I want the horizontal layout to displa ...