Skip to content Skip to sidebar Skip to footer

Angular 2 Routing Refresh

I am trying to Implement Hashlocation Strategy out here it is not working please guide me. This is My Angular & Router Version Package.json '@angular/common': '2.0.0', '@angula

Solution 1:

You only need to change on app.routes.ts

import { ModuleWithProviders }  from '@angular/core';

import { Routes, RouterModule } from '@angular/router';

import { HomeComponent } from './home/home.component';

import { UserListComponent } from './users/user-list.component';

import { ScheduleListComponent } from './schedules/schedule-list.component';

import { ScheduleEditComponent } from './schedules/schedule-edit.component';

const appRoutes: Routes = [

{ path: 'users', component: UserListComponent },

{ path: 'schedules', component: ScheduleListComponent },

{ path: 'schedules/:id/edit', component: ScheduleEditComponent },

{ path: '', component: HomeComponent }

];
export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes, { 

useHash: true });


**Replace above code with below code** 

import { ModuleWithProviders }  from '@angular/core';

import { Routes, RouterModule } from '@angular/router';

import { HomeComponent } from './home/home.component';

import { UserListComponent } from './users/user-list.component';

import { ScheduleListComponent } from './schedules/schedule-list.component';

import { ScheduleEditComponent } from './schedules/schedule-edit.component';

const appRoutes: Routes = [

{ path: '', redirectTo: 'users', pathMatch: 'full' },

{ path: 'users', component: UserListComponent },

{ path: 'schedules', component: ScheduleListComponent },  

{ path: 'schedules/:id/edit', component: ScheduleEditComponent },

];

export const appRoutingProviders: any[] = [
];

export const routing = RouterModule.forRoot(appRoutes);

Post a Comment for "Angular 2 Routing Refresh"