admin管理员组文章数量:1289986
I'm working on a micro frontend for an app I'm building and I want it to have routing. After generating my components and creating a routes.ts
file, I realized there is no app.config.ts
file to bootstrap them to the library. I'm using Angular 19 with standalone components and the only info I can find on the matter is from older versions of angular using NgModule
and RouterModule
. I came across a github bug report from back in 2019 where someone was asking why they're not getting a prompt for if they want to add routing to their libraries upon generating and one of the maintainers had this to say:
In the current setup, prompting users to configure the router doesn't seem the most ergonomic setup. So we decided to change the prompt configuration until we have a way to provision separate defaults for angular and typescript libs.
You can read the report here. Have they figured that out yet or made a solid decision since to just not allow routing in libraries? Even at the time that person in the report didn't necessarily say we couldn't add routing anymore, they just removed the option from the prompt configuration which sounds like setting things up manually should still be an option.
The only thing I could think to try is adding the provideRouter()
method to the providers
array on my main component but that didn't work. Is there a way to set up routing in a library or should I not build my micro frontends as libraries if they need routing?
I'm working on a micro frontend for an app I'm building and I want it to have routing. After generating my components and creating a routes.ts
file, I realized there is no app.config.ts
file to bootstrap them to the library. I'm using Angular 19 with standalone components and the only info I can find on the matter is from older versions of angular using NgModule
and RouterModule
. I came across a github bug report from back in 2019 where someone was asking why they're not getting a prompt for if they want to add routing to their libraries upon generating and one of the maintainers had this to say:
In the current setup, prompting users to configure the router doesn't seem the most ergonomic setup. So we decided to change the prompt configuration until we have a way to provision separate defaults for angular and typescript libs.
You can read the report here. Have they figured that out yet or made a solid decision since to just not allow routing in libraries? Even at the time that person in the report didn't necessarily say we couldn't add routing anymore, they just removed the option from the prompt configuration which sounds like setting things up manually should still be an option.
The only thing I could think to try is adding the provideRouter()
method to the providers
array on my main component but that didn't work. Is there a way to set up routing in a library or should I not build my micro frontends as libraries if they need routing?
1 Answer
Reset to default 0In the provider of app.config.ts add provideRouter() and you can pass your routes in that
routes.ts
export routes: Route[] = [...]
app.config.ts import the routes than
export const appConfig: ApplicationConfig = {
providers: [
provideRouter(routes)
]
}
本文标签: nrwl nxHow do we add routing to an Angular libraryStack Overflow
版权声明:本文标题:nrwl nx - How do we add routing to an Angular library? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741448268a2379331.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
*if
conditions through my templates to toggle things on and off would make things a bit cumbersome so routing felt like the better solution. – Optiq Commented Feb 20 at 20:34