Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

I have an angular 2 app which is working fine except for the routing. It is running alongside an MVC5 asp.net app.

The issue is that it always goes to the default route. That is to say, that none of the routes that I provide find a match.

   @RouteConfig([
        { path: '/Page1', name: 'Page1', component: Page1Component, useAsDefault: true },
        { path: '/Page2', name: 'Page2', component: DPage2Component, useAsDefault: false }
  ])

If I try to navigate to: "localhost:8000/Page2" then the MVC view for Page2 is loaded correctly, but then the url is changed to localhost:8000/Page2/Page1 and the angular app for Page1 will load.

I have tried using <base href="/"> in the head of the html page and I have tried with and without the / slashed in the path, but none of there seem to match.

My MVC route config is as follows:

   app.UseMvc(config =>
      {
        config.MapRoute(
          name: "Default",
          template: "{controller}/{action}/{id?}",
          defaults: new { controller = "Home", action = "Index" }
          );
      });

Any ideas on this? Even some logging would be helpful.

I have tried switching from angular2 beta8 to beta 16, but this has not resolved the issue.

share|improve this question
1  
Only with these infos is hard to help you. What I can say is you don't need to declare useAsDefault: false. Just omit it when it is false. Another advice: upgrade your Angular lib to the latest version (currently RC 4) as soon as possible because the router component you're using is deprecated and a lot of things have changed with the new router component. – Bernardo Pacheco Aug 3 at 2:16
1  
What does your mvc route config look like and do you have any rewrite rules set? – garethb Aug 3 at 4:02
    
Thanks for the advice. I will look to upgrade soon and use the new router soon. I will edit the question to include my MVC route config.No rewrite rules used. Thanks both for your advice. – Sam Aug 4 at 19:49

Try using the following in config.MapRoute

app.UseMvc(config =>
  {
    config.MapRoute(
      name: "Default",
      url: "{*.}",
      defaults: new { controller = "Home", action = "Index" }
      );
  });

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.