0

I am getting started with angular 2 and meteor, so i created a simple app and tried to get the child routers working. Everything is fine so far, i do have a nested state like

/products/milk

main.ts

@RouteConfig([
    { path: '/',             name: 'Home',     component: Home },
    { path: '/products/...', name: 'Products', component: Products },
    { path: '/**',           redirectTo: ['Home'] }
])

products.ts

@RouteConfig([
    { path: '/',   name: 'ProductTeaser', component: ProductsTeaser, useAsDefault: true },
    { path: '/milk', name: 'Milk',          component: Milk },
    { path: '/**',    redirectTo: ['ProductTeaser'] }
])

From the application itself getting to the nested route is no problem, but if i try to load the url (products/milk) in the browser directly the state does not load (the index.html is there, and the app contructor is called)

If i go to /products it works as intended, but not for 2nd level routes

Can anyone help me with this issue?

Update 1: As i do not know how to effectively showing this issue in a plunkr / fiddle, i am just putting all the contents here.

app.ts

import 'reflect-metadata';
import 'zone.js/dist/zone';

import {Component, provide} from 'angular2/core';
import {bootstrap} from 'angular2-meteor-auto-bootstrap';
import {ROUTER_PROVIDERS, ROUTER_DIRECTIVES, RouteConfig, APP_BASE_HREF} from 'angular2/router';
import {Home} from "./imports/home/home";
import {Products} from "./imports/products/products";
import {Admin} from "./imports/admin/admin";
import {Header} from "./imports/components/header/header";

@Component({
    selector: 'app',
    templateUrl: 'client/app.html',
    directives: [ROUTER_DIRECTIVES, Header]
})

@RouteConfig([
    { path: '/',             name: 'Home',     component: Home },
    { path: '/admin',        name: 'Admin',    component: Admin },
    { path: '/products/...', name: 'Products', component: Products },
    { path: '/**',           redirectTo: ['Home'] }
])

class Dairy {
    constructor() {
    }
}

bootstrap(Dairy, [
    ROUTER_PROVIDERS,
    provide(APP_BASE_HREF, { useValue : '/' })
]);

app html

<div class="container-fluid">
    <div class="container content">
        <router-outlet></router-outlet>
    </div>
</div>

products.ts

import 'reflect-metadata';
import {Component} from 'angular2/core';
import {Milk} from "./milk/milk";
import {RouteConfig, RouterOutlet} from "angular2/router";
import {ProductsTeaser} from "./products-teaser/products-teaser";

@Component({
    selector: 'products',
    templateUrl: '/client/imports/products/products.html',
    directives: [RouterOutlet]
})

@RouteConfig([
    { path: '/',   name: 'ProductTeaser', component: ProductsTeaser, useAsDefault: true },
    { path: '/milk', name: 'Milk',          component: Milk },
    { path: '/**',    redirectTo: ['ProductTeaser'] }
])

export class Products{

}

products html

<h1>All products</h1>
<div>
    <router-outlet></router-outlet>
</div>

Update 2:

I am using angular 2.0.0-beta.15

The server is METEOR@1.3.2.4

I am navigating to the state by a link like:

<a [routerLink]="['Products', 'Milk']">Milk</a>

Same behaviour on Chrome 50 and IE 11

From a comment to a deleted answer

Using the HashLocationStrategy is working, but it is not what i want. AFAIK angular 2 should be able to resolve the state as it gets loaded (app constructor is called). I am not getting a 404 the server redirects the request correctly

Update 3: I started working with firebase, everything works perfectly there, so it seems to me that this is a kind of server related thing.

pfried
  • 5,000
  • 2
  • 38
  • 71
  • That's not enough information to debug the issue. How do the components look like (`template`, `directives`, ``). How does `bootstrap()` look like?` – Günter Zöchbauer Apr 24 '16 at 14:00
  • @GünterZöchbauer I know it is really hard to debug, i posted only the relevant files i think. Remember it is working when i go from the root state to the child state, but if i click in the url bar and hit enter, the state does not get resolved again – pfried Apr 24 '16 at 14:17
  • It's probably http://stackoverflow.com/questions/35137573/angular-2-router-es5-doesnt-work-on-page-reload/35137712#35137712 – Günter Zöchbauer Apr 24 '16 at 14:21
  • No idea, the [**Plunker**](https://plnkr.co/edit/5aL9Uj?p=preview) I created might still be helpful for others trying to solve the issue – Günter Zöchbauer Apr 24 '16 at 14:46
  • Thanks for the plunker, is there any way to investigate the issue with the plunker? I found no way to reload the browser on the route as i am getting a 404 then – pfried Apr 24 '16 at 14:51
  • 1
    No, but it's easy to copy the file to a local project and run it locally. At least others don't have the work to figure out which components are necessary to be able to run the project without errors. – Günter Zöchbauer Apr 24 '16 at 14:53
  • Okay i see, but were you able to reproduce the issue? Do you understand my problem? Thanks for your help – pfried Apr 24 '16 at 14:55
  • I don't have a server set up where I can test `PathLocationStrategy`. – Günter Zöchbauer Apr 24 '16 at 14:56

0 Answers0