如何删除“#”而又不会在刷新Ionic中的页面时出错

时间:2018-06-28 05:12:31

标签: html angular url ionic3

我正在构建一个离子型PWA,在其中已实现了深层链接。

 IonicModule.forRoot(MyApp, {}, {
            links: [
                { component: FeaturedPage, name: 'FeaturedPage', segment: ':title' },
                { component: HomePage, name: 'HomePage', segment: ':title' },
                { component: LatestPage, name: 'LatestPage', segment: ':title' },
                { component: TopPage, name: 'TopPage', segment: ':title' },
                { component: TrendingPage, name: 'TrendingPage', segment: ':title' },
                { component: ListPage, name: 'ListPage', segment: ':title' },
                { component: ItemDetailsPage, name: 'ItemDetailsPage', segment: 'Categories/:category' }
            ]
        }),

默认情况下,它将生成一个包含“#”的URL。 enter image description here

根据要求,我必须删除“#”,因此我进行了研究,发现在以下帮助下,我可以从URL中删除“#”。

import { LocationStrategy, PathLocationStrategy } from '@angular/common';

{ provide: LocationStrategy, useClass: PathLocationStrategy },

我取得了成功。现在,URL不包含“#” enter image description here

但是,当我刷新此页面时,我得到了一个错误 enter image description here

我知道,为了克服这种类型的错误,需要在URL中放入“#”,但是现在我不需要“#”,也不需要刷新页面后出现错误,有没有人可以让我知道如何摆脱这种情况?

0 个答案:

没有答案