Я понимаю, что могу удалить хеш из моего URL -
http://localhost:4200/#/pages/login
, установив это -
{
Обеспечить: LocationStrategy,useClass: HashLocationStrategy}
с этим -
{предоставить: LocationStrategy, useClass: PathLocationStrategy}
Но затем я обнаружил, что нам также нужно изменить конфигурацию нашего веб-сервера,потому что при маршрутизации через URL в приложении не отображается ни одна страница, даже -> 404. Not Found.
Я даже реализовал в приложении -
.routing.ts
export class AppRoutingModule {
constructor(private router: Router) {
this.router.errorHandler = (error: any) => {
let routerError = error.toString();
if (routerError.indexOf('Cannot match any routes') >= 0 ) {
this.router.navigate(['/pages/login']);
} else {
throw error;
}
}
}
Но безрезультатно.Я использую Ubuntu, поэтому я полагаю, что любые настройки в IIS отбрасываются, и я даже не смог найти замену IIS в Ubuntu, пожалуйста, помогите.
UPDATE
angular-cli.json
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"project": {
"version": "1.0.0-alpha.6",
"name": "coreui-angular"
},
"apps": [
{
"root": "src",
"outDir": "dist",
"assets": [
"assets"
],
"index": "index.html",
"main": "main.ts",
"polyfills": "polyfills.ts",
"test": "test.ts",
"tsconfig": "tsconfig.app.json",
"testTsconfig": "tsconfig.spec.json",
"prefix": "app",
"styles": [
"scss/style.scss"
],
"scripts": [
"../node_modules/chart.js/dist/Chart.bundle.min.js",
"../node_modules/chart.js/dist/Chart.min.js"
],
"environmentSource": "environments/environment.ts",
"environments": {
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}
}
],
"e2e": {
"protractor": {
"config": "./protractor.conf.js"
}
},
"lint": [
{
"project": "src/tsconfig.app.json"
},
{
"project": "src/tsconfig.spec.json"
},
{
"project": "e2e/tsconfig.e2e.json"
}
],
"test": {
"karma": {
"config": "./karma.conf.js"
}
},
"defaults": {
"styleExt": "scss",
"prefixInterfaces": false,
"serve": {
"port": 4200,
"host": "localhost"
}
}
}
index.html
<head>
<base href="./">
//code for links like bootstrap ,etc.
</head>
app.routing.ts
import { NgModule } from '@angular/core';
import { Routes, RouterModule,Router } from '@angular/router';
import { HttpModule } from '@angular/http';
// Layouts
import { FullLayoutComponent } from './layouts/full-layout.component';
import { SimpleLayoutComponent } from './layouts/simple-
layout.component';
import { AuthGuard } from './authguard/authguard';
export const routes: Routes = [
{
path: '',
redirectTo: 'pages/login',
pathMatch: 'full',
},
{
path: '',
component: FullLayoutComponent,
children: [
{
path: 'dashboard',
loadChildren: './dashboard/dashboard.module#DashboardModule',
canActivate: [AuthGuard],
data: [{
title: 'Master Systems'
},
{
expectedRole: '18'
},
{
expectedRole: '0'
},
]
},
{
path: 'components',
loadChildren: './components/components.module#ComponentsModule',
canActivate: [AuthGuard],
data: [{
title: 'Master Systems'
}
]
},
//code
@NgModule({
imports: [RouterModule.forRoot(routes )],
exports: [RouterModule]
})
export class AppRoutingModule {
constructor(private router: Router) {
this.router.errorHandler = (error: any) => {
let routerError = error.toString();
if (routerError.indexOf('Cannot match any routes') >= 0 ) {
this.router.navigate(['/pages/login']);
} else {
throw error;
}
}
}
}