角度模块href不起作用

时间:2018-04-01 16:53:31

标签: angular angular-ui-router http-status-code-404 href

我有一个应用程序,该应用程序与ng服务器(localhost:4200)配合使用,但当我使用命令ng build --env prod --base-href / dashboard2 /部署它时,root可以正常工作,但模块指示404错误。

import { ModuleWithProviders } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';

//Importar componentes
import { LoginComponent } from './login/login.component';
import { HomeComponent } from './home/home.component';
import { DashboardComponent } from './dashboard/dashboard.component';
import { UserProfileComponent } from './user-profile/user-profile.component';
import { CreateUserComponent } from './create-user/create-user.component';


const appRoutes: Routes = [
    {path:'', component: LoginComponent},
    {path:'dashboard', component: DashboardComponent},
    {path:'login', component: LoginComponent},
    {path:'user-profile',   component: UserProfileComponent },
    {path:'create-user', component:CreateUserComponent},
    {path:'home', component: HomeComponent},
    {path:'**', component: LoginComponent}
];

export const appRoutingProviders: any[] = [];

export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes);

2 个答案:

答案 0 :(得分:0)

尝试以下命令:

ng build --prod --base-href /PROJECT_NAME/

答案 1 :(得分:0)

如果您使用PathLocationSTrategy(默认),则需要为令牌APP_BASE_HREF指定基本标记和提供者。您是否已将此行添加到@NgModule装饰器?

providers: [{provide: APP_BASE_HREF, useValue: '/dashboard2'}]

APP_BASE_HREF会影响路由器解析应用内routerLinkrouter.navigate()次呼叫的方式。



<base href="...">代码会影响浏览器在加载<link><script><img>等静态资源时解析网址的方式。