Completing our route configuration

As promised in previous sections, I will share the entire source code of AppModule, including the route configurations. The following code may look lengthy or scary, but trust me, it's actually very simple and straightforward. 

During the course of learning this chapter, we have generated many components and created their route paths. We are just importing the components and updating appRoutes with their paths. That's it. I promise.

Here is the complete listing of the app.module.ts file:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { AppComponent } from './app.component';
import { HomeComponent } from './home/home.component';
import { SignupComponent } from './signup/signup.component';
import { LoginComponent } from './login/login.component';
import { ListingsComponent } from './listings/listings.component';
import {ListingDetailsComponent } from './listing-deatails/listing-details.component';
import { EditListingComponent } from './edit-listing/edit-listing.component';
import { PreviewListingComponent } from './preview-listing/preview-listing.component';
import { PhotosComponent } from './photos/photos.component';
import { UploadPhotoComponent } from './upload-photo/upload-photo.component';
import { EditPhotoComponent } from './edit-photo/edit-photo.component';
import { PreviewPhotoComponent } from './preview-photo/preview-photo.component';
import { PageNotFoundComponent } from './page-not-found/page-not-found.component';
import { FeaturesComponent } from './features/features.component';
import { PricingComponent } from './pricing/pricing.component';
import { AboutComponent } from './about/about.component';
import { SupportComponent } from './support/support.component';
import { AccountComponent } from './account/account.component';
import { LogoutComponent } from './logout/logout.component';

const appRoutes: Routes = [
{ path: 'home', component: HomeComponent },
{ path: '', redirectTo: '/home', pathMatch: 'full' },
{ path: 'signup', component: SignupComponent },
{ path: 'login', component: LoginComponent },
{ path: 'logout', component: LogoutComponent },
{ path: 'account', component: AccountComponent },
{ path: 'features', component: FeaturesComponent },
{ path: 'pricing', component: PricingComponent },
{ path: 'about', component: AboutComponent },
{ path: 'support', component: SupportComponent },
{ path: 'listings', component: ListingsComponent },
{ path: 'listing/:id', component: ListingDetailsComponent },
{ path: 'listing/edit', component: EditListingComponent },
{ path: 'listing/preview', component: PreviewListingComponent },
{ path: 'photos', component: PhotosComponent },
{ path: 'photo/upload', component: UploadPhotoComponent },
{ path: 'photo/edit', component: EditPhotoComponent },
{ path: 'photo/preview', component: PreviewPhotoComponent },
{ path: '**', component: PageNotFoundComponent }
];
@NgModule({
declarations: [
AppComponent,
HomeComponent,
SignupComponent,
LoginComponent,
ListingsComponent,
CreateListingComponent,
EditListingComponent,
PreviewListingComponent,
PhotosComponent,
UploadPhotoComponent,
EditPhotoComponent,
PreviewPhotoComponent,
PageNotFoundComponent,
FeaturesComponent,
PricingComponent,
AboutComponent,
SupportComponent,
AccountComponent,
LogoutComponent
],
imports: [
BrowserModule,
RouterModule.forRoot(appRoutes)
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }

We have just created our routes, but we will need to update our template file by creating a few links that will have the path to the aforementioned-defined routes.

One thing that's most important in any application is a well-designed menu, which helps guide users and adds to a good user experience.

Using the Bootstrap nav component, we will design a menu for our application in the next section.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.149.239.82