【问题标题】:Excel Angular Web Add-In Error: Cannot match any routes. URL Segment: 'index.html'Excel Angular Web 加载项错误:无法匹配任何路由。 URL 段:'index.html'
【发布时间】:2018-09-14 16:17:53
【问题描述】:

在我的 Excel Angular Web 插件中,导航到新路线时出现以下错误:

ERROR 错误:未捕获(在承诺中):错误:无法匹配任何路由。 URL 段:'index.html'

但是,这些路线仍然有效。我该如何解决这个问题?

【问题讨论】:

    标签: excel angular office-js excel-addins exceljs


    【解决方案1】:

    由于某种原因,当包含 Office.js 时,Angular 2+ 会在路由中附加一个 #。例如,我的加载项的默认 url 路径是 http://localhost:3000/#/

    因此,我必须更新我的路由模块以使用哈希:

    RouterModule.forRoot(appRoutes, { useHash: true })

    代替:

    RouterModule.forRoot(appRoutes)

    参考: https://docs.microsoft.com/en-us/office/dev/add-ins/develop/add-ins-with-angular2#use-the-hash-location-strategy-in-the-angular-application

    【讨论】:

    • 我很高兴你没有被阻止,但为了记录,Office.js 不会在路由中添加 #。 Angular 基础架构会在某些情况下执行此操作。是否获得 # 取决于您的 Angular 定位策略和路由配置。您的更改实施了哈希定位策略。
    • @RickKirkham 我认为还有更多。在修复之前,如果我在 Edge 或 Chrome 中打开 Web 插件,URL 会不断地附加一个“/#”,实际上导致 Chrome 崩溃。实验我删除了office.js,然后重新启动了应用程序。 “/#”不再附加,更改路线不会产生错误。为什么包含 office.js 会导致这种行为?
    • 我恐怕不知道为什么加载Office.js会影响Angular定位策略。我只是想说明 Office.js 没有将“/#”添加到 URL 的代码。 Office.js 的加载会导致 Angular 添加该字符串。正如您所发现的,您必须使用哈希定位策略。我在制作这个样本时发现了同样的事情:github.com/OfficeDev/Word-Add-in-Angular2-StyleChecker/blob/…
    猜你喜欢
    • 2017-09-25
    • 2019-06-16
    • 2017-11-13
    • 2022-08-18
    • 1970-01-01
    • 2021-07-05
    • 2019-01-16
    • 1970-01-01
    • 2019-05-11
    相关资源
    最近更新 更多