【发布时间】:2020-10-24 00:45:30
【问题描述】:
我有一个登录页面和另一个主页,问题是在生产中如果您不通过登录,您将无法进入主页,也就是说......如果我这样做了
ng build --prod --base-href /project/
在生产中,如果我访问 http://xx.xxx.xxx.x/project 它可以工作,但如果我在导航栏中输入 http://xx.xxx.xxx.x/project/home 或 http://xx.xxx.xxx.x/project/login 给出未找到 404
如果我在登录或主页中并且我重新加载页面,它也会给我同样的错误,这让我再次输入路由:http://xx.xxx.xxx.x/project
通过登录进入主页。通过执行 ng 服务,这在本地对我很有效,但在生产中却不行。
我的路由代码:
const routes: Routes = [
{
path: '',
pathMatch: 'full',
redirectTo: 'login'
},
{
path: 'login',
component: LoginComponent
},
{
path: '',
component: MainLayoutComponent,
canActivateChild: [AuthGuard],
children: [
{
path: 'home',
component: HomeComponent,
canActivate: [AuthGuard]
},
{
path: 'config',
component: ConfigComponent,
canActivate: [AuthGuard]
},
]
},
];
【问题讨论】:
标签: angular routes url-routing