首页 > 解决方案 > 如何删除“#”而不会在 Ionic 中刷新页面时出错

问题描述

我正在构建一个 Ionic 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。 在此处输入图像描述

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

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

{ provide: LocationStrategy, useClass: PathLocationStrategy },

我在结果上取得了成功。现在 URL 不包含“#” 在此处输入图像描述

但是,当我刷新此页面时,出现错误 在此处输入图像描述

我知道,为了克服这种错误,需要在 URL 中加上“#”,但现在我不想有“#”,也不想刷新页面后出现错误,有没有人,谁能告诉我,如何摆脱这个?

标签: htmlangularurlionic3

解决方案


推荐阅读