Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ionic framework 如何使用Ionic-4中的路由浏览同一页面?_Ionic Framework_Ionic4_Angular7 Router - Fatal编程技术网

Ionic framework 如何使用Ionic-4中的路由浏览同一页面?

Ionic framework 如何使用Ionic-4中的路由浏览同一页面?,ionic-framework,ionic4,angular7-router,Ionic Framework,Ionic4,Angular7 Router,我想在Ionic 4中使用路由浏览同一页面 我已经尝试过这段代码,但没有正常工作this.navCtrl.navigateRoot('super') 我希望页面导航到Ionic 4中的同一页面,以导航到页面使用: this.navCtrl.navigateRoot('/route'); this.navCtrl.navigateRoot(['/route',object]); 您应该像这样指定页面路由 const routes: Routes = [ { path: 'login', c

我想在Ionic 4中使用路由浏览同一页面

我已经尝试过这段代码,但没有正常工作
this.navCtrl.navigateRoot('super')


我希望页面导航到Ionic 4中的同一页面,以导航到页面使用:

this.navCtrl.navigateRoot('/route');
this.navCtrl.navigateRoot(['/route',object]);
您应该像这样指定页面路由

const routes: Routes = [
  { path: 'login', component: LoginPage },
  { path: 'home', component: HomePage },
  { path: 'detail/:id', component: DetailPage },
  { path: '', redirectTo: '/login', pathMatch: 'full'}
];

您可以阅读更多详细信息来导航到页面使用:

this.navCtrl.navigateRoot('/route');
this.navCtrl.navigateRoot(['/route',object]);
您应该像这样指定页面路由

const routes: Routes = [
  { path: 'login', component: LoginPage },
  { path: 'home', component: HomePage },
  { path: 'detail/:id', component: DetailPage },
  { path: '', redirectTo: '/login', pathMatch: 'full'}
];

您可以阅读更多详细信息来导航到页面使用:

this.navCtrl.navigateRoot('/route');
this.navCtrl.navigateRoot(['/route',object]);

要导航到页面,请使用:

this.navCtrl.navigateRoot('/route');
this.navCtrl.navigateRoot(['/route',object]);

最好的方法是设置,告诉angular重新加载。 如果没有,黑客将使用
navigateByUrl

this.router.navigateByUrl(`/super/${id}`);

通过这种方式,您将传递一个参数,重新加载将完成,因为angular检测到一个不同的url并导航到它(如果当前页面没有相同的传递id)。不过,在这种情况下,这不是最漂亮的方法。只是一个变通办法。

最好的办法是设置,告诉angular重新加载。
{
    path: '',
    component: MyPage
  },
  {
    path: ':id',
    component: MyPage
  }
如果没有,黑客将使用
navigateByUrl

this.router.navigateByUrl(`/super/${id}`);

通过这种方式,您将传递一个参数,重新加载将完成,因为angular检测到一个不同的url并导航到它(如果当前页面没有相同的传递id)。不过,在这种情况下,这不是最漂亮的方法。只是修一下。

它工作不正常。我想在同一个函数上调用同一个页面,而不使用ngoninit()。你是说要重新加载页面?window.location.reload();window.location.reload();将重新加载当前页面,但我希望它应在前进方向上创建同一页面的新页面对象。我希望类似的内容它无法正常工作。我想在同一个函数上调用同一个页面,而不使用ngoninit()。你是说要重新加载页面?window.location.reload();window.location.reload();将重新加载当前页面,但我希望它应在前进方向上创建同一页面的新页面对象。我希望类似的内容。请不要仅发布代码作为答案,还要解释代码的作用以及它如何解决问题。带解释的答案通常更有帮助,质量更好,更容易吸引读者。请不要只发布代码作为答案,还要解释代码的作用以及它如何解决问题。带有解释的答案通常更有帮助,质量更好,更容易吸引选票
{
    path: '',
    component: MyPage
  },
  {
    path: ':id',
    component: MyPage
  }