相关疑难解决方法(0)

Angular 2/4/5 - 动态设置基本href

我们有一个企业应用程序,它为客户端使用Angular 2.我们每个客户都有自己独特的网址,例如:https://our.app.com/customer-onehttps://our.app.com/customer-two.目前我们可以<base href...>动态设置document.location.所以用户点击https://our.app.com/customer-two<base href...>设置为/customer-two......完美!

问题是,如果用户是例如,https://our.app.com/customer-two/another-page并且他们刷新页面或尝试直接点击该URL,则<base href...>设置为get /customer-two/another-page并且找不到资源.

我们尝试了以下无济于事:

<!doctype html>
<html>

<head>
  <script type='text/javascript'>
    var base = document.location.pathname.split('/')[1];
    document.write('<base href="/' + base + '" />');
  </script>

...
Run Code Online (Sandbox Code Playgroud)

不幸的是,我们的想法很新鲜.任何帮助都会很棒.

angular

107
推荐指数
9
解决办法
12万
查看次数

标签 统计

angular ×1