gpt4 book ai didi

Electron 中的 Angular 路由

转载 作者:行者123 更新时间:2023-12-03 12:39:23 25 4
gpt4 key购买 nike

我的 Angular Electron 桌面应用程序中的页面路由似乎遇到了一些问题。我以与在 Angular 应用程序中相同的方式设置路由,但没有任何效果。我使用 routerlink="/home"作为 html 文件中的路由,并且我已经在 app.routing.module 中设置了组件的路径。我有一个 sidenav 和一个应该路由到相同页面的工具栏,以及一个应该在应用程序启动时加载的注册页面登录,但没有任何反应。

const routes: Routes = [
{path: 'Insurnace',component:InsuranceProviderComponent},
{path: '**',component: PageNotFoundComponent},
{path:'profile',component:ProfileComponent},
// // {path: '',redirectTo: '/home',pathMatch: 'full'},
// {path: '**',redirectTo: '/home',pathMatch: 'full'},
{path:'login',component:LoginComponent},
{path:'register',component:RegisterComponent},
{path:'insurance',component:InsuranceProviderComponent},
{path:'farm',component:FarmComponent}
];
the routing paths

<mat-toolbar color="primary" class="tool">
<mat-toolbar-row>
<button mat-icon-button>
<mat-icon (click)="sidenav.toggle()">menu</mat-icon>
</button>
<h1 id="name">AgriLog</h1>
<span class="menu-spacer"></span>
<div>
<a mat-button [routerLink]="'/home'"><span class="material-icons">
home_work
</span>Home</a>
<a mat-button [routerLink]="'/about'"><span class="material-icons">
info
</span>About</a>
<a mat-button [routerLink]="'/profile'"><span class="material-icons">
account_circle
</span>Profile</a>
<!-- <a mat-button [routerLink]="'/farm'"><span class="material-icons">
agriculture
</span>Farm</a> -->
<a mat-button id="reglog" [routerLink]="'/register'"><span class="material-icons">
person_add
</span>Register</a>
<a mat-button id="reglog" [routerLink]="'/login'"><span class="material-icons">
login
</span>Login</a>
<a mat-button id="reglog" [routerLink]="'/'"><span class="material-icons">
power_settings_new
</span>Logout</a>
</div>
</mat-toolbar-row>
</mat-toolbar>


<mat-sidenav-container class="side" layout="vertical" layout-fill flex>
<mat-sidenav #sidenav>
<mat-nav-list>
<br>
<br>
<br>
<a mat-list-item [routerLink]="'./farm'"><span class="material-icons">
home_work
</span>Home</a>
<a mat-list-item [routerLink]="'/about'"><span class="material-icons">
info
</span>About</a>
<a mat-list-item [routerLink]="'./profile'"><span class="material-icons">
account_circle
</span>Profile</a>
<!-- <a mat-list-item [routerLink]="'/farm'"><span class="material-icons">
agriculture
</span>Farms</a> -->
<a mat-list-item [routerLink]="'/'"><span class="material-icons">
power_settings_new
</span>Logout</a>
<a mat-list-item (click)="sidenav.toggle()" href="" mat-list-item>Close</a>
</mat-nav-list>
</mat-sidenav>
<mat-sidenav-content>
<div style="height: 100vh;">
<router-outlet></router-outlet>
</div>
</mat-sidenav-content>
</mat-sidenav-container>

最佳答案

在 Angular 中生成的根页面将为 <base href="/"> ,这会在 Electron 中产生问题。

更新<base href="/"><base href="./">src/index.html

在你的 main.js win.loadUrl检查文件名和路径是否正确!

function createWindow () {
// Create the browser window.
win = new BrowserWindow({
width: 600,
height: 600,
backgroundColor: '#ffffff',
icon: `file://${__dirname}/dist/assets/logo.png`
})


win.loadURL(`file://${__dirname}/dist/index.html`) <== HERE
}

希望这有效!

关于 Electron 中的 Angular 路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63339971/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com