V
V
Valentine2016-03-24 10:25:57
JavaScript
Valentine, 2016-03-24 10:25:57

Why does routing work incorrectly in Angular 2?

Good day to all! I would like to clarify one question from knowledgeable people: why routing in Angular 2 does not work for me as intended:
Application root ( app.component.ts ):

import {Component} from 'angular2/core';
import {RouteConfig, Router, ROUTER_DIRECTIVES} from 'angular2/router';

import {Home} from './home/home.component';
import {AdminRoot} from './admin/adminRoot.component';


@Component({
  selector: 'app',
  pipes: [],
  providers: [],
  directives: [ROUTER_DIRECTIVES],
  styles: [''],
  template: require('./app.html')
})
@RouteConfig([
  {path: '/', name: 'Index', component: Home},
  {path: '/home', name: 'Home', component: Home, useAsDefault: true},
  {
    path: '/admin',
    name: 'AdminRoot',
    loader: () => require('es6-promise!./admin/adminRoot.component')('AdminRoot')
  }])
export class App {
  constructor() { }
}

And then I do all the successors in the same way: '/tables' (further routing when switching to /admin), because the usual way with /admin/... does not work for me, i.e. it loads all the files but does not display anything , I note that this was both with and without webpack:
1643ea606f9b4ed6928c90ccb5c1dd68.png
I would have left everything anyway, it works the same. But this was a temporary measure, because you can’t share the link: tratata.ru/tables/uniqproduct/info. Because only the child chunk will be downloaded + the necessary libraries (they are directly connected to index.html), but it would be necessary to download the ancestors. And even then, with almost 100% probability nothing will happen, because the scheme described above does not work.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Zuev, 2016-03-24
@Waynes

Do it the right way, through /admin/... . If there are difficulties, then read this answer from SO.
There is an example in the Angular documentation itself

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question