Как остаться на той же angular странице после обновления sh браузера - PullRequest
0 голосов
/ 28 февраля 2020

Я занимаюсь разработкой angular приложения. Каждый раз, когда refre sh браузер, приложение перемещается на домашнюю страницу. Любой способ остаться на той же странице?

Обновление: вот маршруты приложения.

export const secureRoutes: Routes = [
{path: '', component: DashboardComponent,  pathMatch: 'full'},
{ path: 'dashboard', component: DashboardComponent, canActivate: [AuthGuard] },
{ path: 'user', component: UserComponent, canActivate: [AuthGuard] },
{ path: 'table', component: TableComponent, canActivate: [AuthGuard] },
{ path: 'typography', component: TypographyComponent, canActivate: [AuthGuard] },
{ path: 'icons', component: IconsComponent, canActivate: [AuthGuard] },
{ path: 'maps', component: MapsComponent, canActivate: [AuthGuard] },
{ path: 'notifications', component: NotificationsComponent, canActivate: [AuthGuard] },
{ path: 'upgrade', component: UpgradeComponent, canActivate: [AuthGuard] },
{ path: 'categories/new', component: AddEditCategoryComponent, canActivate: [AuthGuard] },
{ path: 'categories/view/:id', component: ViewCategoryComponent, canActivate: [AuthGuard] },
{ path: 'categories/edit/:id', component: AddEditCategoryComponent, canActivate: [AuthGuard] },
{ path: 'categories', component: CategoriesComponent, canActivate: [AuthGuard] },
{ path: 'categories/:category_id/view_product/:product_id',
        component: ViewProductComponent, canActivate: [AuthGuard] },
{ path: 'categories/:category_id/new_product', component: AddEditProductComponent, canActivate: [AuthGuard] },
{ path: 'categories/:category_id/edit_product/:product_id',
      component: AddEditProductComponent, canActivate: [AuthGuard] },
{ path: 'settings', component: SettingsComponent, canActivate: [AuthGuard] },
{ path: 'settings/edit', component: EditSettingsComponent, canActivate: [AuthGuard] },
{ path: 'users', component: UsersComponent, canActivate: [AuthGuard] },
{ path: 'users/view_client/:id', component: ClientComponent, canActivate: [AuthGuard] },
{ path: 'orders', component: OrdersComponent, canActivate: [AuthGuard], },
{ path: 'orders/:type/:id', component: OrderComponent, canActivate: [AuthGuard] },
{ path: 'adgroups', component: AdGroupsComponent, canActivate: [AuthGuard] },
{ path: 'adgroups/new', component: AddEditAdGroupComponent, canActivate: [AuthGuard] },
{ path: 'adgroups/view/:id', component: ViewAdGroupComponent, canActivate: [AuthGuard] },
{
    path: '**',
    component: PageNotFoundComponent
}

];

Здесь также используется AuthGuard, используемый в вышеуказанные маршруты.

    @Injectable()
    export class AuthGuard implements CanActivate {
      constructor(
        private router: Router,
        public afAuth: AngularFireAuth
      ) {
      }
      canActivate(): Observable<boolean> {
        return this.afAuth.authState.pipe(map((user) => {
          if (user) {
            return true;
          }
          this.router.navigate(['/login'])
          return false;
        }))
      }
    }

1 Ответ

0 голосов
/ 28 февраля 2020

Я решил проблему. Маршруты в порядке, но у меня была навигационная панель с функцией переключения языка. Этот переключатель языка вызывается для проверки языка, и при некоторых условиях он переходит на домашнюю страницу.

Спасибо всем.

...