指向页面的角度直接链接重定向到首页

时间:2020-05-11 20:11:14

标签: angular angular8 nebular

我已经使用ngx-admin / nebular / Angular 8创建了一个应用

问题在于,浏览应用程序时,所有内容均按预期工作,但是打开直接链接时,它将重定向到首页,例如链接http://localhost:4200/#/profile甚至是http://localhost:4200/#/profile/123。即使当链接打开时也足够扼杀,当我刷新时,它将带我回家。

我尝试pathMatch: 'full'添加到我的索引/主页,我尝试更改页面的顺序。

app-routing.module.ts

const routes: Routes = [
  {
    path: '',
    loadChildren: () => import('app/pages/pages.module')
      .then(m => m.PagesModule),
  },
  {
    path: 'auth',
    children: [
      {
        path: 'callback/:token',
        component: AuthenticateComponent,
      },
    ],
  },
];

const config: ExtraOptions = {
  useHash: true,
};

pages-routing.module.ts

const routes: Routes = [{
  path: '',
  component: PagesComponent,
  children: [
    {
      path: 'profile/:steamid',
      component: ProfileComponent,
    },
    {
      path: 'profile',
      component: ProfileComponent,
    },
    {
      path: 'server/:serverid',
      component: ServerComponent,
    },
    {
      path: 'home',
      component: HomeComponent,
      pathMatch: 'full',
    },
    {
      path: '',
      component: HomeComponent,
      pathMatch: 'full',
    },
    {
      path: '**',
      component: NotFoundComponent,
    },
  ],
}];

app.component.ts

@Component({
  selector: 'ngx-app',
  template: '<router-outlet></router-outlet>',
})
export class AppComponent implements OnInit {

  constructor() {
  }

  ngOnInit(): void {
  }
}

0 个答案:

没有答案