Angular 刷新后页面已更改
我正在angular 6中创建Instagram克隆,我面临一个问题。 如果我在“我的主页”组件中进行刷新,它会正确地刷新显示我的所有帖子,但如果我在“个人资料”页面上进行刷新,它会自动将我重定向到主页,而不是在“个人资料”页面上进行刷新和保留 刷新后,它仍能正常工作 纵断面图 刷新后 app.routesAngular 刷新后页面已更改,angular,typescript,Angular,Typescript,我正在angular 6中创建Instagram克隆,我面临一个问题。 如果我在“我的主页”组件中进行刷新,它会正确地刷新显示我的所有帖子,但如果我在“个人资料”页面上进行刷新,它会自动将我重定向到主页,而不是在“个人资料”页面上进行刷新和保留 刷新后,它仍能正常工作 纵断面图 刷新后 app.routes import {Routes} from '@angular/router' import { AcessoComponent } from './acesso/acesso.comp
import {Routes} from '@angular/router'
import { AcessoComponent } from './acesso/acesso.component';
import { HomeComponent } from './home/home.component';
import { AutenticacaoGuard } from './autenticacao-guard.service';
import { ProfileComponent } from './profile/profile.component';
export const ROUTES:Routes=[
{path:'', component:AcessoComponent},
{ path: "home", component: HomeComponent, canActivate:[AutenticacaoGuard]},
{ path: "profile", component: ProfileComponent, canActivate:[AutenticacaoGuard]}
]
Profile.ts
export class ProfileComponent implements OnInit {
constructor() { }
ngOnInit() {
}
}
home.ts
export class HomeComponent implements OnInit {
@ViewChild('publicacoes') public publicacoes:any
constructor() { }
ngOnInit() {
}
public atualizarTimeLine(){
this.publicacoes.atualizarTimeLine()
}
}
为什么会发生这种情况?首先,创建一个组件,以防用户输入随机路径,并将其称为
PageNotFound
其次,由于角度开始从上到下匹配输入的路由,因此路由的顺序
数组很重要
最后:考虑将您的<代码>路由< /COD>数组改为:
export const ROUTES:Routes = [
{ path: "home", component: HomeComponent, canActivate:[AutenticacaoGuard]},
{ path: "profile", component: ProfileComponent, canActivate[AutenticacaoGuard]},
{ path: '', redirectTo: '/home', pathMatch: 'full' },
{ path: '**', component: PageNotFoundComponent },
];
我建议您使用问题是,当用户通过身份验证并进行刷新(路径:'')时,应该将其重定向到主页,但如果用户未通过身份验证,则应该将其重定向到accessoComponent(我必须在其中登录表单)。我按照您的说法执行了,但当我写下类似的东西时,它会将我重定向到PageNotFoundComponent,几秒钟后,它会自动将我再次重定向到home component,我不知道为什么