ngRoute set base url for all routes

前端 未结 2 1284
醉梦人生
醉梦人生 2020-11-29 07:39

Is it possible to add a base url to all routes in an AngularJS app? Essentially changing its location on the server (kind of, if that makes sense..

相关标签:
2条回答
  • 2020-11-29 08:23

    Setting the <base> HTML5 tag might help. From the documentation here:

    Relative links

    Be sure to check all relative links, images, scripts etc. You must either specify the url base in the head of your main html file (<base href="/my-base">) or you must use absolute urls (starting with /) everywhere because relative urls will be resolved to absolute urls using the initial absolute url of the document, which is often different from the root of the application.

    Running Angular apps with the History API enabled from document root is strongly encouraged as it takes care of all relative link issues.

    0 讨论(0)
  • 2020-11-29 08:29

    The location for the base href must have trailing /. For example:

    <base href="location" />
    

    will not work. It must be in this format:

    <base href="location/" />
    
    0 讨论(0)
提交回复
热议问题