Browser address will not be displayed correctly in ui-route

前端 未结 2 723
北荒
北荒 2020-12-12 01:17

I am using the following example :

http://angular-ui.github.io/ui-router/sample/#/

Default Page URL in the example above :

 http://angular-u         


        
相关标签:
2条回答
  • 2020-12-12 01:33

    The issue is on the ASP.NET MVC side... we have to be sure, that

    • browser will be using the trailing slash
    • or redirect it, if not...

    This should be the content of your Index action

    public ActionResult Index()
    {
        var root = VirtualPathUtility.ToAbsolute("~/");
        var applicationPath = Request.ApplicationPath;
        var path = Request.Path;
    
        var hasTraillingSlash = 
              root.Equals(applicationPath, StringComparison.InvariantCultureIgnoreCase)
           || !applicationPath.Equals(path, StringComparison.InvariantCultureIgnoreCase);
    
        if (!hasTraillingSlash)
        {
            return Redirect(root + "#");
        }
    
        return View();
    }
    

    Check this Q & A:

    • Workaround for MVC misbehaviour with missing trailing slash
    0 讨论(0)
  • 2020-12-12 01:37

    First, I'm change the templateUrl to

     templateUrl: '/Scripts/ui-route/home/home.html',
    

    Then, I changed the code as follows:

          public ActionResult Index()
            {
                var path = Request.Path;
    
                if (path == "/Admin")
                {
                    return Redirect("/Admin/");
                }
    
                return View();
            }
    

    It works.

    0 讨论(0)
提交回复
热议问题