Hello everyone,

First of all i want to explain why i want to accomplish this.

Explanation:
I'm making a backend where the user can decide how the urls needs be 
visible in the browser / indexers.
To make this work i created a api endpoint called /router.json and also 
/resolve.

My first plan was let the backend decide witch component needs to be 
rendered.
Example:
Angular => ask backend to resolve /home
Angular <= Sever give as response "component: Page, argument: {id:2}"
Angular render Component Page with argument id:2

I spoke with a lot of guys in IRC it seems i did not get this to work with 
the new Angular 2 Router (not deprecated) so i decided to take a step back 
and using they /router.json endpoint

The /router.json endpoint gives all the routers back for example:

[
 {path: '', redirectTo: 'home'},
 {path: 'home', component: 'Home'},
 {path: 'about', component: 'About'},
 {path: '**', redirectTo: 'home'}
]


What i want is that before angular resolves the url, the routings are set i 
didn't find out how i can accomplish this. But i take a step back and added 
in the app.component the following code:


export class App {

 constructor(public http:Http, public router:Router) {
 }

 ngOnInit() {
   this.http.get('/api/1.0/router.json').subscribe(res => {
   this.router.resetConfig(res.json());
 });
 }

}


This didn't work because when you use  component: it needs to resolve to a 
js file and not just the name of the component because it just cannot find 
one.
Error that you get when trying this:

Why this don't work is because i cannot define a JS file because i using 
webpack chunks (see project setup section).
What i can do and that works i creating a function that maps a component 
name 'home' to a pointer that points to component 'Home'.

import {Home} from './home';
import {About} from './app.component';
import {Page} from './page';

export function componentMapping(name:string) {
 switch (name) {
 case 'home':
   return Home;
 break;
 case 'about':
   return About;
 break;
 case 'page':
    return Page;
 break;
 }
}



Questions:
1. Is there a option to use my /resolve endpoint by hooking or writhing my 
own resolving code?
2. How can use my router endpoint before Angular is resolving / routing the 
url
3. How can i resolve (lazy loading) the components names through webpack 
chunks? (i'm now made a componentMapping function that resolves the names 
and loading the components see function above)


Project setup:
https://github.com/angular/universal-starter


Kind regards,
Lennard

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to