如何使默认路由在无需添加活动函数的情况下显示一个应用程序
我正在使用单SPA框架,大多数情况都进展顺利。
使用单SPA-Layout,我添加了一个默认路由,当URL与我定义的路由不匹配时,应显示该路由。如果默认根的孩子只是一些html节点/s,则可以正常工作
<template id="single-spa-layout">
<single-spa-router mode="history" base="/">
<route default>
<h1>404 - No page mathes the URL</h1>
</route>
<route path="login">
<application name="@my-company/mf-login"></application>
</route>
</single-spa-router>
</template>
我的问题是,如果我想在默认根中路由到特定的应用程序(MF默认),则除非我注册我的应用程序并提供Activewhen()函数,否则不会显示它例如,
<template id="single-spa-layout">
<single-spa-router mode="history" base="/">
<route default>
<application name="@my-company/mf-default"></application>
</route>
<route path="login">
<application name="@my-company/mf-login"></application>
</route>
</single-spa-router>
</template>
registerApplication({
name: "@my-company/mf-default",
app: () => {
return System.import("@my-company/mf-default");
},
activeWhen: () => shouldBeActive,
});
我不确定为什么我需要提供何时应显示默认404应用程序的逻辑(在我的示例中,这是应该反应的部分),因为它已经知道URL是否匹配已知路线,这证明了这一事实证明了这一事实。我的第一个示例起作用,只有在路由真正不匹配的情况下,只有HTML表明HTML。
任何人都可以启发我如何工作。我绝对需要显示404个硬编码的HTML不仅仅需要显示一些硬编码的HTML,在这种情况下,我需要显示特定的应用程序。
我应该指出,如果我将其设置为True,那么确实显示了404应用程序,因此没有任何技术限制。但是我不明白为什么我需要为这种情况提供Activewhen()函数,因为框架已经知道何时不匹配路线。
即使可以访问框架用于计算路由匹配的功能,我可以将其重复使用。
对此的任何帮助将不胜感激。我敢肯定,答案也可能对他人有所帮助。谢谢
I am using single-spa framework and most things are going well.
Using the single-spa-layout I have added a default route which should be displayed when the url does not match a route that I have defined. This works properly if the child of the default root is just some html node/s e.g.
<template id="single-spa-layout">
<single-spa-router mode="history" base="/">
<route default>
<h1>404 - No page mathes the URL</h1>
</route>
<route path="login">
<application name="@my-company/mf-login"></application>
</route>
</single-spa-router>
</template>
My problem is that if I want to route to particular application (mf-default in my case) in the default root instead it does not show unless I register my application and provide the activeWhen() function just like I would with all my other applications e.g
<template id="single-spa-layout">
<single-spa-router mode="history" base="/">
<route default>
<application name="@my-company/mf-default"></application>
</route>
<route path="login">
<application name="@my-company/mf-login"></application>
</route>
</single-spa-router>
</template>
registerApplication({
name: "@my-company/mf-default",
app: () => {
return System.import("@my-company/mf-default");
},
activeWhen: () => shouldBeActive,
});
I am not sure why I would need to provide the logic for when the default 404 application should be displayed (in my example this is the shouldBeActive part) as it already knows if the URl matched a known route, as evidenced by the fact that my first example works and only shows that HTML whenever the route genuinely doesn't match.
Can anybody enlighten me as to how this should work please. I definitely need to display more than just some hardcoded HTML for a 404 - I need to display a specific application in this case my mf-default application.
I should state that if I set shouldBeActive to true then the 404 application is indeed displayed so there is no technical limitation that disallows it. But I am not understanding why I need to provide activeWhen() function for this case at all as the framework already knows when a route doesn't match.
Even having access to the function that the framework uses to calculate a routeMatch would help as I could reuse that.
Any help on this would be greatly appreciated. I'm sure an answer on this could be helpful to others too. Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论