angular / router

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

Abstract routes for implementing layouts #203

Open xmlking opened 9 years ago

xmlking commented 9 years ago

How to I implement multiple layouts that are parents for sub set of routes by default? E.g: I have some routes for pre-login users that has one layout theam and some routes for post-login users with different layout theam.

brettstack commented 9 years ago

+1

Simon-Li commented 9 years ago

+1

btford commented 9 years ago

To better understand – you want the same URL, but totally different content based on app state?

brettstack commented 9 years ago

https://github.com/angular-ui/ui-router/wiki/Nested-States-and-Nested-Views#abstract-states

btford commented 9 years ago

Yes, I know UI router has a thing called "Abstract Routes."

I'm curious what the use case is.

brettstack commented 9 years ago

Sorry for the hasty reply. I was in a meeting. I use them quite a bit to serve as containers/groupings for child states. They allow you to set a base path, template and logic that is used by all child states without allowing that state to be accessed directly (you can only access a concrete child state). A good example of this is unauthenticated and authenticated states. The two templates are very different, and one important piece of logic is as well (do not allow unauthenticated users access to authenticated states). But you wouldn't want to have 'authenticated' and 'unauthenticated' in your URL.

Another use case is for child resources. Say I have a state at the path clients/1. In the abstract state I request data from the server for that client so that all child states have the client data. I could also create a template that adds to the breadcrumb or adds a 'Clients' heading to the page. I could create a child concrete state that has the same path as the abstract state which lists details about the client. Since this has the same path as the abstract state, this can be thought of as the default state. I can then create another child state at path clients/1/friends to list the clients friends.

On Thu, 30 Apr 2015 5:54 pm Brian Ford notifications@github.com wrote:

Yes, I know UI router has a thing called "Abstract Routes."

I'm curious what the use case is.

— Reply to this email directly or view it on GitHub https://github.com/angular/router/issues/203#issuecomment-98011320.

xmlking commented 9 years ago

here I am referring Layout as a abstract component (with a html template with ng-viewports and optional controller)
all my routes (pages) will inherit one of the available Layouts
Layout will never be associated with a route since it is an abstract component.

martinmicunda commented 9 years ago

+1

yarsh commented 8 years ago

+1

tjn487 commented 6 years ago

+1

I'm using this feature from ui-router and want to upgrade my angular 1.5.x based application to angular latest version 5.x or 6.x but latest angular router still doesn't support this feature.

Is there any plan to implement this feature?

ViieeS commented 5 years ago

@tjn487 I'm not sure, but we can try to do it like this:

const routes: Routes = [
  {
    path: '', component: AbstractComponent,
    children: [
      {path: 'some', component: SomeComponent}
    ]
  },
];
xmlking commented 5 years ago

I am using this pattens for this usecase https://github.com/xmlking/ngx-starter-kit/blob/develop/libs/dashboard/src/lib/dashboard.module.ts