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

僤鯓⒐⒋嵵緔 提交于 2019-12-14 04:04:50

问题


Iam working on ionic2 project. In that I have login page along with four tabs. At first the login page has to be appear.

For that I have placed

rootPage:any = LoginPage

for making login page as root page.

It works perfectly. But my problem is on browser refresh,the page reloads and navigated to login page again without staying in current page.

I have changed the root page to current page name and it works perfectly. But I have two modules containing different tabs so for that I cannot give particular tab name in rootPage. How can I navigate the page to current page on browser refresh?


回答1:


It seems like you are not using lazy loading for your LoginPage at least. So your best bet might be to use the Deeplinks Ionic native plugin.

Deeplinks

It enables you to use simple routing logic in the form:

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);
});

Lazy loading

If you can turn your pages into modules, you will automatically have a path for each page in the form of:

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

In the @IonicPage() decorator of a page component you can even specify the page's name and the "segment" to use in the 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 {
    // ...
}


来源:https://stackoverflow.com/questions/48662104/how-to-navigate-to-current-page-itself-on-browser-refresh-in-ionic2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!