我在我的角度2應用中使用queryParams
和params
。而我堅持的問題:重新加載頁面後我的網址扭曲。重新加載后角度2網址的更改
與params
:
重裝後:
與queryParams
:
重裝後:
routes.ts
import { ModuleWithProviders } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { HomeComponent } from './components/home/home.component';
import { LoginComponent } from './components/login/login.component';
import { RegisterComponent } from './components/register/register.component';
import { AlbumsComponent } from './components/albums/albums.component';
import { AddAlbumComponent } from './components/albums/add-album.component';
import { AddImageAlbumComponent } from './components/albums/add-image-album.component';
import { AlbumDetailComponent } from './components/albums/album-detail.component';
import { PhotosComponent } from './components/photos/photos.component';
import { UsersComponent } from './components/users/users.component';
import { AuthGuard } from './guards/auth.guard'
const appRoutes: Routes = [
{ path: '', component: HomeComponent },
{ path: 'login', component: LoginComponent },
{ path: 'register', component: RegisterComponent },
{ path: 'albums', component: AlbumsComponent, canActivate: [AuthGuard] },
{ path: 'add-album', component: AddAlbumComponent, canActivate: [AuthGuard] },
{ path: 'add-image-album/:id', component: AddImageAlbumComponent, canActivate: [AuthGuard] },
{ path: 'albums/:id', component: AlbumDetailComponent, canActivate: [AuthGuard] },
{ path: 'photos', component : PhotosComponent, canActivate: [AuthGuard] },
{ path: 'users', component : UsersComponent, canActivate: [AuthGuard] }
];
export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes);
導航與params
:
[routerLink]="['/albums/:id', {id: album.id}]
導航與queryParams
:
[queryParams]="{user_id: dataService.getCurrentUserId()}"
看起來你的導航代碼有問題。你可以在你處理導航的地方顯示你的組件嗎? –
我有同樣的問題。 – aycanadal