Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Cannot find primary outlet to load 'MyComponent' #2636

Closed
chadbr opened this issue Oct 10, 2016 · 2 comments
Closed

Error: Cannot find primary outlet to load 'MyComponent' #2636

chadbr opened this issue Oct 10, 2016 · 2 comments

Comments

@chadbr
Copy link

chadbr commented Oct 10, 2016

Please provide us with the following information:

OS?

Mac OSX

Versions.

angular-cli: 1.0.0-beta.17
node: 6.7.0
os: darwin x64

Repro steps.

Migration of RC4 app to release. I generated a skeleton with ng new and I'm migrating code from existing project.

The log given by the failure.

When I try to go to my routes - they tell me the components don't exist

logging-error-handler.ts:58Uncaught (in promise): Error: Cannot find primary outlet to load 'StyleGuideComponent'LoggingErrorHandler.handleError @ logging-error-handler.ts:58
logging-error-handler.ts:59Error: Uncaught (in promise): Error: Cannot find primary outlet to load 'StyleGuideComponent'
at resolvePromise (zone.js:429)
at zone.js:406
at ZoneDelegate.invoke (zone.js:203)
at Object.onInvoke (ng_zone_impl.js:43)
at ZoneDelegate.invoke (zone.js:202)
at Zone.run (zone.js:96)
at zone.js:462
at ZoneDelegate.invokeTask (zone.js:236)
at Object.onInvokeTask (ng_zone_impl.js:34)
at ZoneDelegate.invokeTask (zone.js:235)

Mention any other details that might be useful.

Here's my app-routing.module.ts (simplified):

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';

import { StyleGuideComponent } from './assets/style-guide/style-guide.component';

const routes: Routes = [
  { path: '', redirectTo: '/style-guide', pathMatch: 'full' },
  { path: 'style-guide', component: StyleGuideComponent }
];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule],
  providers: []
})
export class MyAppRoutingModule { }

and my app.module.ts (again, simplified)

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { RouterModule } from '@angular/router';

import { AppComponent } from './app.component';
import { MaterialModule } from '@angular/material';

import { MyAppRoutingModule } from './app-routing.module';

import { StyleGuideComponent } from './assets/style-guide/style-guide.component';

@NgModule({
  declarations: [
    AppComponent,
    StyleGuideComponent

  ],
  imports: [
    BrowserModule,
    FormsModule,
    RouterModule,
    HttpModule,
    MaterialModule.forRoot(),
    MyAppRoutingModule
  ],

  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

I get the same issue trying to route to any of the other components.... Any ideas?

@chadbr
Copy link
Author

chadbr commented Oct 10, 2016

Ok, sorry to pollute the water... This turned out to be a behavior change in routing. I'll leave it here in case it helps someone else.

I had a conditional around my <router-outlet> -- that doesn't work anymore.

<div class="main-body" *ngIf="user && user.authorized">
  <router-outlet></router-outlet>
</div>

angular/angular#11100

you need to use a route guard
https://angular.io/docs/ts/latest/guide/router.html#!#guards
https://angular.io/docs/ts/latest/guide/router.html#!#resolve-guard

Thanks -- Chad

@chadbr chadbr closed this as completed Oct 10, 2016
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
@chadbr and others