admin管理员组文章数量:1289506
I have an Angular (18.2) + Electron (26) application which requires the HashLocation whereas when running on the web does not need this.
Within the standard app.config.ts I simply use the below for Electron
provideRouter: (routes, withHashLocation())
How can I make this dynamic so that withHashLocation is not added when not Electron?
The only way to check if the Angular site is running under Electron is with the below statement which feels like it isn't accessible when the app.config.ts is loaded.
this.windowReference.api && this.windowReference.api.isElectron
I have an Angular (18.2) + Electron (26) application which requires the HashLocation whereas when running on the web does not need this.
Within the standard app.config.ts I simply use the below for Electron
provideRouter: (routes, withHashLocation())
How can I make this dynamic so that withHashLocation is not added when not Electron?
The only way to check if the Angular site is running under Electron is with the below statement which feels like it isn't accessible when the app.config.ts is loaded.
this.windowReference.api && this.windowReference.api.isElectron
Share
Improve this question
asked Feb 20 at 12:32
Mad EddieMad Eddie
1,2273 gold badges15 silver badges28 bronze badges
1 Answer
Reset to default 2You could try to export the route providers to a separate variable and conditionally assign it based on the environment like this (inside app.config.ts
):
const isElectron = this.windowReference?.api?.isElectron; // may have to use window?.api?.isElectron since app.config.ts is a module.
const routerProviders = isElectron ? provideRouter(routes, withHashLocation()) : provideRouter(routes);
export const appConfig: ApplicationConfig = {
providers: [routerProviders]
};
本文标签: electronAngular conditional provideRouter featuresStack Overflow
版权声明:本文标题:electron - Angular conditional provideRouter features - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741435230a2378597.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论