binding classes for component activated by router-outlet
- Dominant language
- TypeScript
- Stars
- 101k
- Forks
- 27.5k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 288
Description
### Which @angular/* package(s) are relevant/related to the feature request?
router
### Description
For an Angular UI library like [Clarity](https://clarity.design/), regarding the [application layout](https://clarity.design/documentation/app-layout), `.content-container` class is required for the top level route components.
I'd like to propose a feature request about _binding classes for component activated by `router-outlet`_.
### Proposed solution
Add an `@Input() componentClass = ''` to `router-outlet` directive.
Aafter `this.activated` is initialized, add the classes to the created or attached component as following:
```typescript
this.activated.location.nativeElement.classList.add(...this.componentClass.split(' '));
```
### Alternatives considered
Currently, as mentioned above, for each route component, the following codes should be added in the `@Component` metadata:
```
host: {
'[class.content-container]': 'true',
},
```
Adding `componentClass` to router-outlet solves it more directly and concisely.
Contributor guide
Research direction
Start at the router-outlet directive entry point and inspect how activated or attached components are handled. Determine where a componentClass input would apply classes and how existing router-outlet tests cover activation; done means the requested classes are applied to routed components without breaking existing behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- angular, typescript
- Domain
- frontend
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100