我们有一个企业应用程序,它为客户端使用Angular 2.我们每个客户都有自己独特的网址,例如:https://our.app.com/customer-one和https://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)
不幸的是,我们的想法很新鲜.任何帮助都会很棒.
我正在开发一个需要根据某些外部数据源配置路由的应用程序.应用程序的生命周期如下所示:
实际上有一个带有routesService的另一层抽象,但这个例子不需要
该部分工作,因为我们从主页开始,进行API调用并routerConfigs为每个类别创建.因此,当用户单击某个类别时,路径已经配置了正确的categoryComponent+,metadata并且它们会显示正确的信息.
但是,如果直接访问某个特定的类别页面,那么ng2还没有routerConfigfor the route,因为API调用还没有返回任何内容,更不用说了.Ng2只是使用Header,Footer和一个空路由器来呈现基本应用程序.
我能想到的唯一解决方案就是"hacky".将缓存的json文件保存在应用服务器上并在初始html中加载,然后将其注入ng2 bootstrap/init中的服务.这样,在ng2甚至生物之前配置路线以呈现页面.
我要求任何其他可能的建议,也许有一些我可以接受的更多ng2经验的人.也许这已经解决了,我还没有完善我的google-fu.
提前致谢.