0

I am using Angular 10 in Asp.net MVC project.

I am getting below error in the routing. Here is my routing code.

app-routing.module.ts

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { StoreComponent } from './store/store.component';
import { CartComponent } from './cart/cart.component';

const routes: Routes = [
  { path: '', component: StoreComponent },
  { path: 'cart', component: CartComponent }
];

@NgModule({
   imports: [RouterModule.forRoot(routes)],
   exports: [RouterModule]
})
export class AppRoutingModule { }

app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { StoreComponent } from './store/store.component';
import { CartComponent } from './cart/cart.component';

@NgModule({
  declarations: [
    AppComponent,
    StoreComponent,
    CartComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

app.component.html

<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
      <ul class="nav navbar-nav">
        <li><a [routerLink]="['/']">Store</a></li>
        <li><a [routerLink]="['/cart']">Cart</a></li>
      </ul>
    </div><!-- /.navbar-collapse -->
  </div><!-- /.container-fluid -->
</nav>
<div class="container">
  <router-outlet></router-outlet>
</div>

So as per the code is has two menus, store and cart and expected result respectively is,

store works!

cart works!

But is shows blank page with no error in console.

pankaj bawdane
  • 101
  • 4
  • 18
  • 1
    Try adding the following to your first path: `{ path: '', component: StoreComponent, pathMatch: 'full' },` – Jeremy Jul 28 '20 at 15:32
  • @JeremyLucas Tried.It gave errror "Failed to load resource: the server responded with a status of 404 (Not Found)" – pankaj bawdane Jul 28 '20 at 15:46

0 Answers0