0

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.

3
  • 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. Commented Aug 3, 2016 at 2:16
  • 1
    What does your mvc route config look like and do you have any rewrite rules set? Commented Aug 3, 2016 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. Commented Aug 4, 2016 at 19:49

1 Answer 1

1

Try using the following in config.MapRoute

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

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.