0

I am developing a mini SPA, using angular, inside my ASP.Net MVC 5 application. Basically I want to use this mini SPA for onboarding/registration workflow, and use ASP.Net MVC views and routes for other functionality.

For Onboarding mini SPA I have defined an MVC route:

routes.MapRoute(
           name: "Onboarding",
           url: "onboarding/{*catchall}",
           defaults: new { controller = "Onboarding", action = "Create" }
       );

The Angular configuration looks like:

(function () {
var app = angular.module('app', ['ngRoute']);
app.config(function ($routeProvider, $locationProvider) {

    $routeProvider.caseInsensitiveMatch = true;
    $routeProvider.when('/onboarding', { templateUrl: '/app/Views/CreateShop.html', controller: 'onboardingController' })
        .when('/onboarding/add-product', { templateUrl: '/app/Views/AddProduct.html', controller: 'onboardingController' })

    $locationProvider.html5Mode(true);
});}());

The Create.chtml uses acts as a container/entry point for this mini SPA.

    <div ng-controller="onboardingController">
    <div ng-view></div>
</div>
@section scripts {
    @Scripts.Render("~/bundles/angularOnboarding")
}

PROBLEM: When I am inside the mini SPA my navigation links/routes break e.g. navigation to contact page or about page (MVC Views) doesn't work. Angular seems to handling all routing requests. Also, navigation from an anchor tag which navigates to some MVC route doesn't work. Putting the url in the browser works. How do I make this work for my hybrid scenario? Would really appreciate any suggestions or solution, Thanks.

Amanvir Mundra
  • 420
  • 1
  • 6
  • 20
  • I found a couple of workarounds, but none seem to be perfect fit for my needs. A couple of solutions explained here: http://stackoverflow.com/questions/11580004/angular-js-link-behaviour-disable-deep-linking-for-specific-urls. Adding target="_self" to links is supposed to work, but that means I have to add an additional attribute to all links. – Amanvir Mundra Mar 16 '15 at 17:24
  • $locationProvider.html5Mode({ enabled: true, rewriteLinks: false }); This seems to do a full page reload even for pages inside the SPA. – Amanvir Mundra Mar 16 '15 at 17:30
  • Did you find the solution for this!? – Thirisangu Ramanathan Mar 20 '18 at 05:07

0 Answers0