Угловой 6 и роутер - PullRequest
0 голосов
/ 10 июня 2018

Доброе утро, у меня есть вопрос о маршрутизаторах, я определил мой app.routing.module.ts:

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


const APP_ROUTES: Routes = [
  {path: 'livros', loadChildren: './livros/livros.module'},
];

@NgModule({
  imports: [RouterModule.forRoot(APP_ROUTES)],
  exports: [RouterModule]
})


export class AppRoutingModule {}

и мой livros.routing.module.ts:

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

import {LivrosComponent} from './livros.component';

const LIVROS_ROUTES: Routes = [
  {path: '', component: LivrosComponent},
];

@NgModule({
  imports: [RouterModule.forChild(LIVROS_ROUTES)],
  exports: [RouterModule]
})

export class LivrosRoutingModule {}

Когда я запускаю свое приложение, я получаю эту ошибку:

Ошибка типа: router.initialNavigation не является функцией в RouterInitializer.push ../ node_modules/@angular/router/fesm5/router.js.RouterInitializer.bootstrapListener(router.js: 5067) в core.js: 4467 в Array.forEach () в ApplicationRef.push ../ node_modules/@angular/core/fesm5/core.js.ApplicationRef._loadComponent (core.js: 4467) вApplicationRef.push ../ node_modules/@angular/core/fesm5/core.js.ApplicationRef.bootstrap (core.js: 4405) в core.js: 4205 в Array.forEach () в PlatformRef.push ../ node_modules /@ angular / core / fesm5 / core.js.PlatformRef._moduleDoBootstrap (core.js: 4205) в core.js: 4172 в ZoneDelegate.push ../ node_modules / zone.js / dist / zone.js.ZoneDelegate.invoke (zone.js: 388)

Я искал решение и настроил app.routing.module.ts с initialNavigation: false:

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


const APP_ROUTES: Routes = [
  {path: 'livros', loadChildren: './livros/livros.module'},
];

@NgModule({
  imports: [RouterModule.forRoot(APP_ROUTES, {initialNavigation: false})],
  exports: [RouterModule]
})


export class AppRoutingModule {}

но я получаю новую проблему:

TypeError: router.setUpLocationChangeListener не является функцией в RouterInitializer.push ../ node_modules / @ angular / router / fesm5 / router.js.RouterInitializer.bootstrapListener (router.js: 5070) в core.js: 4467 в Array.forEach () в ApplicationRef.push ../ node_modules/@angular/core/fesm5/core.js.ApplicationRef._loadComponent (core).js: 4467) в ApplicationRef.push ../ node_modules/@angular/core/fesm5/core.js.ApplicationRef.bootstrap (core.js: 4405) в core.js: 4205 в Array.forEach () в PlatformRef.push ../ node_modules/@angular/core/fesm5/core.js.PlatformRef._moduleDoBootstrap (core.js: 4205) в core.js: 4172 в ZoneDelegate.push ../ node_modules / zone.js / dist / zone.js.ZoneDelegate.invoke (zone.js: 388)

У вас есть новая конфигурация в версии 6?Как я могу решить эту проблему?Что случилось в моем приложении?Спасибо.

1 Ответ

0 голосов
/ 10 июня 2018

ОК

{
  "name": "nodebook-front",
  "version": "0.0.0",
  "scripts": {
    "ng": "node_modules/.bin/ng",
    "start": "ng serve "
},
  "private": true,
  "dependencies": {
    "@angular/animations": "^6.0.4",
    "@angular/cdk": "^6.2.1",
    "@angular/common": "^6.0.4",
    "@angular/compiler": "^6.0.4",
    "@angular/core": "^6.0.4",
    "@angular/forms": "^6.0.4",
    "@angular/http": "^6.0.4",
    "@angular/material": "^6.2.1",
    "@angular/platform-browser": "^6.0.4",
    "@angular/platform-browser-dynamic": "^6.0.4",
    "@angular/router": "^6.0.4",
    "@ng-bootstrap/ng-bootstrap": "^2.1.0",
    "bootstrap": "^4.1.1",
    "core-js": "^2.5.7",
    "font-awesome": "^4.7.0",
    "hammerjs": "^2.0.8",
    "primeng": "6.0.0-beta.1",
    "quill": "^1.3.6",
    "rxjs": "^6.2.0",
    "zone.js": "^0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^0.6.8",
    "@angular/cli": "^6.0.8",
    "@angular/compiler-cli": "^6.0.4",
    "@angular/language-service": "^6.0.4",
    "@types/jasmine": "^2.8.8",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "codelyzer": "~4.2.1",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "^2.0.2",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~1.4.2",
    "karma-jasmine": "~1.1.1",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.3.0",
    "ts-node": "~5.0.1",
    "tslint": "~5.9.1",
    "typescript": "~2.7.2"
  }
}

[ИЗД.]

enter image description here

структура моего проекта

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...