angular / router

The Angular 1 Component Router
MIT License
665 stars 135 forks source link

How to you route to folders that are not a direct child of ./components? #379

Open ghost opened 8 years ago

ghost commented 8 years ago

Hi,

All the examples I've seen, have routes that navigate to components that are in folders that are first children of /components. This great for demo-ware, but a real app needs much mores structure.

How to I set up my routes for:

./components /home

/sales /orders /customers /reporting

So I need to route to components under ./components/sales/orders as well as components under ./components/home

How do I configure routing in these scenarios?

Very much appreciated!!!

Karl

sirajc commented 8 years ago

For your scenario, lets assume you have OrderComponent in ./components/sales/orders for which you need to configure route in HomeComponent under ./components/home. Now Routes in Angular needs to know the path and the component, So in HomeComponent write following import import { OrderComponent } from '../sales/orders'; Now, add RouteConfig on HomeComponent as follows

@RouteConfig([
  {
    path: '/orders',
    as: 'Orders',
    component: OrderComponent
  }
])
export HomeComponent { 
ghost commented 8 years ago

@sirajc thank you very much.

Does this work in ES5? Not sure I can use, "import { OrderComponent } from '../sales/orders';" in a ES5 JavaScript file.

Sorry for the New Bee question!

Thank you again,

Karl