typescript - Relative paths not work in angular -


when i'm on `http://localhost/overview', module loaded along path:

http://localhost/app/modules/overview/overview.module.js

but when turn page http://localhost/overview/users , press f5 (refresh page), error:

error: unexpected token <   evaluating http://localhost/overview/app/modules/overview/overview.module 

the error occurred because url not correct, should http://localhost/app/modules/overview/overview.module.

how make work properly?

this project structure:

enter image description here

this systemjs tsconfig:

{   "compileonsave": true,   "compileroptions": {     "target": "es5",     "module": "commonjs",     "moduleresolution": "node",     "sourcemap": true,     "emitdecoratormetadata": true,     "experimentaldecorators": true,     "lib": [ "es2015", "dom" ],     "noimplicitany": false,     "suppressimplicitanyindexerrors": true   } } 

this systemjs config:

(function (global) {     system.config({         baseurl: "/",         paths: {             'npm:': '/node_modules/'         },         map: {             app: 'app',              '@angular/core': 'npm:@angular/core/bundles/core.umd.js',             '@angular/common': 'npm:@angular/common/bundles/common.umd.js',             '@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',             '@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',             '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',             '@angular/http': 'npm:@angular/http/bundles/http.umd.js',             '@angular/router': 'npm:@angular/router/bundles/router.umd.js',             '@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',              '@angular/material': 'npm:@angular/material/bundles/material.umd.js',              // cdk individual packages             '@angular/cdk/platform': 'npm:@angular/cdk/bundles/cdk-platform.umd.js',             '@angular/cdk/a11y': 'npm:@angular/cdk/bundles/cdk-a11y.umd.js',             '@angular/cdk/bidi': 'npm:@angular/cdk/bundles/cdk-bidi.umd.js',             '@angular/cdk/observers': 'npm:@angular/cdk/bundles/cdk-observers.umd.js',             '@angular/cdk/overlay': 'npm:@angular/cdk/bundles/cdk-overlay.umd.js',             '@angular/cdk/portal': 'npm:@angular/cdk/bundles/cdk-portal.umd.js',             '@angular/cdk/scrolling': 'npm:@angular/cdk/bundles/cdk-scrolling.umd.js',             '@angular/cdk/keycodes': 'npm:@angular/cdk/bundles/cdk-keycodes.umd.js',             '@angular/cdk/coercion': 'npm:@angular/cdk/bundles/cdk-coercion.umd.js',             '@angular/cdk/collections': 'npm:@angular/cdk/bundles/cdk-collections.umd.js',             '@angular/cdk/rxjs': 'npm:@angular/cdk/bundles/cdk-rxjs.umd.js',             '@angular/cdk/table': 'npm:@angular/cdk/bundles/cdk-table.umd.js',             '@angular/animations': 'npm:@angular/animations/bundles/animations.umd.js',             '@angular/animations/browser': 'npm:@angular/animations/bundles/animations-browser.umd.js',             '@angular/platform-browser/animations': 'npm:@angular/platform-browser/bundles/platform-browser-animations.umd.js',              'rxjs': 'npm:rxjs'             //custom         },         packages: {             app: {                 main: './bootstrap.js',                 defaultextension: 'js'             },             rxjs: {                 defaultextension: 'js'             }         }     }); })(this); 

update

app-routing.module:

import {routermodule, routes} "@angular/router"; import {ngmodule} "@angular/core"; import {loginformcomponent} "./modules/auth/login-form/login-form.component";  const routes :routes = [     {path: "auth", component: loginformcomponent},     {path: "overview", loadchildren: "./app/modules/overview/overview.module#overviewmodule"} ];  @ngmodule({     imports: [routermodule.forroot(routes)],     exports: [routermodule] }) export class approutingmodule{  } 

overview.routing.module:

import {routermodule, routes} "@angular/router"; import {ngmodule} "@angular/core"; import {overviewcomponent} "./overview/overview.component";  const routes :routes = [     {path: "", component: overviewcomponent, children:[         {path: "users", loadchildren: "/app/modules/users/users.module#usersmodule"}     ]} ];  @ngmodule({     imports: [routermodule.forchild(routes)],     exports: [routermodule] }) export class overviewroutingmodule{  } 

users-routing.module:

import { ngmodule } '@angular/core'; import { routes, routermodule } '@angular/router'; import {userslistcomponent} "./users-list/users-list.component"; import {userelementcomponent} "./user-element/user-element.component";  const routes: routes = [     {path: "", component: userslistcomponent},     {path: ":id", component: userelementcomponent}, ];  @ngmodule({   imports: [routermodule.forchild(routes)],   exports: [routermodule] }) export class usersroutingmodule { } 

in components use module.id, exaple overview.component.ts:

@component({     selector: "overview",     moduleid: module.id,     templateurl: "./overview.component.html",     providers:[         overviewservice     ] }) export class overviewcomponent implements oninit {      constructor(private overviewservice :overviewservice) {}      public ngoninit() {         let data = this.overviewservice.getoverview();         log.info(data);     }  } 

you have leading / in path user module.

change this:

 {path: "users", loadchildren: "app/modules/users/users.module#usersmodule"} 

Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -