Reputation: 50
This is an Angular 2 RC5 Project :
I just started to add parameters to my routes, then this problem appears :
In fact, here is my router :
import {ModuleWithProviders} from '@angular/core';
import {Routes, RouterModule} from '@angular/router';
import {HomeComponent} from './components/home/home.component';
import {LoginComponent} from './components/login/login.component';
import {ProfileDetailsComponent} from './components/profileDetails/profileDetails.component';
const appRoutes: Routes = [
{
path: '',
component: HomeComponent
},
{
path: 'login/:userId',
component: LoginComponent
},
{
path: 'profile/:userId',
component: ProfileDetailsComponent
}
];
export const Routing: ModuleWithProviders = RouterModule.forRoot(appRoutes);
So when I call /login/42, it loads me the LoginComponent :
import { Component } from '@angular/core';
@Component({
moduleId: module.id,
selector: 'login',
templateUrl : "login.component.html"
})
export class LoginComponent { }
And this works. The problem is when I reload the page, I got the previous error :
(SystemJS) XHR error (404 not Found) loading http://localhost:3000/login/app/main.js
it tries to load app/main.ts from the login path I have just added !
Some topics say that this is caused by the catch error in the index.html :
System.import('app/main').catch(function(err){ console.error(err); });
(edit) I also have put the base tag in my index.html file :
<base href="/"/>
Some others spoke about the systemjs.config.js :
(function (global) {
System.config({
paths: {
// paths serve as alias
'npm:': 'node_modules/'
},
// map tells the System loader where to look for things
map: {
// our app is within the app folder
app: 'app',
// angular bundles
'@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/router/upgrade': 'npm:@angular/router/bundles/router-upgrade.umd.js',
'@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',
'@angular/upgrade': 'npm:@angular/upgrade/bundles/upgrade.umd.js',
'@angular/upgrade/static': 'npm:@angular/upgrade/bundles/upgrade-static.umd.js',
// other libraries
'rxjs': 'npm:rxjs',
'angular-in-memory-web-api': 'npm:angular-in-memory-web-api/bundles/in-memory-web-api.umd.js'
},
// packages tells the System loader how to load when no filename and/or no extension
packages: {
app: {
main: 'main.js',
defaultExtension: 'js'
},
rxjs: {
defaultExtension: 'js'
}
}
});
})(this);
If you require me to post another file, don't hesitate ! Thanks !
Upvotes: -1
Views: 1163
Reputation: 50
I have been waiting a long time and fetching lot of URL's.
Finally, I didn't find a solution, but a way to get around the problem :
{
path: 'profile',
component: ProfileDetailsComponent
}
And pass additional data with GET parameter :
/profile?id=20
Hope that will help
Upvotes: 1