gpt4 book ai didi

Angular 在路由时删除 url 中的目录

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

我设置了一个本地 IIS 和一个名为 test 的目录的应用程序:

enter image description here

然后在我的浏览器中,我浏览到:“http://localhost/test

我有一个路线:

const routes: Routes = [
{
path: '', pathMatch: 'full', component: LoginComponent
},
{
path: '**', redirectTo: ''
}
];

@NgModule({
imports: [
RouterModule.forRoot(routes, { preloadingStrategy: PreloadAllModules })
],
exports: [RouterModule]
})

export class AppRoutingModule {}

但是当我到达登录页面时,浏览器去掉了“test”,只做浏览器地址中的“ http://localhost/”,这是错误的。

由于缺少“测试”,浏览器现在也无法获取 Assets :
enter image description here
仅供引用,当我构建应用程序时,我使用 --baseHref=/test/构建它

最佳答案

如果没有匹配的路由,您将其设置为重定向到空白,并且 test 没有一个...

猜测你想在你的构建命令中设置 base href ......

ng build --prod --baseHref=test

文档: https://angular.io/cli/build

您可以在 ng serve 中设置相同的如果您尝试将其作为开发服务器运行。但这似乎是多余的。

关于Angular 在路由时删除 url 中的目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62286381/

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