簡體   English   中英

如何在ionic2中刷新瀏覽器時導航到當前頁面本身?

[英]How to navigate to current page itself on browser refresh in ionic2?

Iam正在ionic2項目上工作。 在那我有四個選項卡的登錄頁面。 首先,必須顯示登錄頁面。

為此,我將

rootPage:any = LoginPage

將登錄頁面作為根頁面。

它運作完美。 但是我的問題是在瀏覽器刷新上,頁面重新加載並再次導航到登錄頁面,而沒有停留在當前頁面上。

我已經將根頁面更改為當前頁面名稱,並且可以正常運行。 但是我有兩個包含不同選項卡的模塊,因此無法在rootPage指定特定的選項卡名稱。 如何在瀏覽器刷新時將頁面導航到當前頁面?

看來您至少沒有對LoginPage使用延遲加載。 因此,最好的選擇是使用Deeplinks Ionic本機插件。

深層連結

它使您可以使用以下形式的簡單路由邏輯:

this.deeplinks.route({
    '/about-us': AboutPage,
    '/universal-links-test': AboutPage,
    '/products/:productId': ProductPage
}).subscribe((match) => {
    // match.$route - the route we matched, which is the matched entry from the arguments to route()
    // match.$args - the args passed in the link
    // match.$link - the full link data
    console.log('Successfully matched route', match);
}, (nomatch) => {
    // nomatch.$link - the full link data
    console.error('Got a deeplink that didn\'t match', nomatch);
});

延遲加載

如果您可以將頁面轉換為模塊,則將自動為每個頁面提供路徑,格式為:

http://localhost:8100/#/my-page

在頁面組件的@IonicPage()裝飾器中,您甚至可以指定頁面名稱和要在URL中使用的“段”:

import { Component, OnInit } from '@angular/core';
import { IonicPage, NavController, NavParams, Platform } from 'ionic-angular';

@IonicPage({
    name: 'customPageName',
    segment: 'custom-path'
})
@Component({
    selector: 'page-device',
    templateUrl: 'device.html',
})
export class MyPage implements OnInit {
    // ...
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM