0

I have just upgraded from router-deprecated to "@angular/router": "3.0.0-alpha.8". I have everything working inside the application but it's not working when I navigate to a URL.

For example, I use this routerLink:

<a [routerLink]="['/app/dashboard']">DashBoard</a>

which produces this URL:

http://localhost:54675/app/dashboard

And that view loads with no problem.

However, if I just enter that URL in the browser and press return I get a blank white page. Nothing in the console and the source is empty.

I am using the default HTML5 locationStrategy - not the hash (#).

This worked with router-deprecated.

I can't figure out what I could be doing wrong since everything else is working.

When I navigate to a fill URL I notice that I get a 404 error in the console. That's because nothing on the server matches this URL, but it needs to load the app then route to that URL.

Here are my route files: app.routes.ts:

export const routes: RouterConfig = ([
    { path: '', component: SplashComponent },
    { path: 'login', component: SplashComponent },
    ...MainRoutes
]);
export const APP_ROUTER_PROVIDERS = [
    provideRouter(routes)
];

main.routes.ts

export const MainRoutes: RouterConfig = [
    {
        path: 'app',
        component: MainLayoutComponent,
        children: [
                { path: 'dashboard', component: DashboardComponent},
                { path: '', component: DashboardComponent },
                { path: 'user', component: AccountEditComponent },
                { path: 'admin', component: ManageComponent }
            ]
    }
];
2
  • can you add your routes.ts file? Commented Jun 30, 2016 at 19:37
  • When I navigate to a fill URL I notice that I get a 404 error in the console. That's because nothing on the server matches this URL, but it needs to load the app then route to that URL. I updated the question with this info. Commented Jul 5, 2016 at 15:43

1 Answer 1

1

My Angular2 app was hosted in an DotNet Core application. I had to configure it to redirect to index.html on URLs that returned 404s. I followed this article:

http://asp.net-hacker.rocks/2016/04/04/aspnetcore-and-angular2-part1.html

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.