我在角度项目上使用useHash。 但是之后,这样的网址是错误的。
http://localhost:4200/#http://localhost:4200/
这是我的路由模块
import {NgModule} from '@angular/core';
import {Routes, RouterModule} from '@angular/router';
import {Error404PageComponent, Error404PageResolver} from './core';
import {ModalComponent} from './pages/modal/modal.component';
import {MainComponent} from './front/main/main.component';
import {ContactComponent} from './front/contact/contact.component';
import {AboutComponent} from './front/about/about.component';
import {LoginComponent} from './front/auth/login.component';
import {RegisterComponent} from './front/auth/register.component';
import {SuccessComponent} from './payment/success/success.component';
import {CancelComponent} from './payment/cancel/cancel.component';
这是路线。
const routes: Routes = [
{path: '', component: MainComponent},
{path: 'contact', component: ContactComponent},
{path: 'about', component: AboutComponent},
{path: 'login', component: LoginComponent},
{path: 'register', component: RegisterComponent},
{path: 'success', component: SuccessComponent},
{path: 'cancel', component: CancelComponent},
{
path: 'pages',
loadChildren: () => import('./pages/pages.module').then(m => m.PagesModule)
},
{
path: '**',
component: Error404PageComponent,
resolve: {data: Error404PageResolver}
}
];
我在这里添加了userHash。
@NgModule({
imports: [RouterModule.forRoot(routes, {useHash : true})],
exports: [RouterModule],
entryComponents: [
ModalComponent,
]
})
export class AppRoutingModule {
}
所有内容在网站上都能正常运行。
只有网址是错误的。
请让我知道原因