Router UI + Angular routing?

blov · · 548 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>Hello everyone. I hope anyone can give me a heads up with this. I have a barebone working project where I have a Go API and the front end works with angular. The Go server also serve the static files. Took me a while to get it running since I followed this code for the angular part (<a href="https://github.com/johnpapa/gulp-patterns" rel="nofollow">https://github.com/johnpapa/gulp-patterns</a>)</p> <p>Anyway, to the point, the go server is configured so it serves the /app/ path to static files. Now, my questions is, what do I do to urls where there is no actual file. Like I have the following url &#34;<a href="http://sugar.com/app/nofile" rel="nofollow">http://sugar.com/app/nofile</a>&#34;. Right now, the go servers answers 404, but I want the router ui to handle it and work his magic.</p> <p>Any ideas would be welcome. Thanks redditors.</p> <hr/>**评论:**<br/><br/>synalx: <pre><p>Hi!</p> <p>So, once your application loads, the Angular router will look at the URL and do the right thing. The trick is that a request for /app/nofile needs to cause the application to load. The easiest way to do that is to serve the application HTML (index.html file typically) at /app/nofile in addition to /app, and making sure all paths for resources in index.html are resolved relative to /app and not /app/some/route/you/have.</p></pre>CaptaincCodeman: <pre><p>It boils down to handling 404 errors on the server and serving out the index.html page or whatever loads your client side app.</p> <p>Once thing to note is that because your page can be loading from any path, you probably need to set the base href in the index.html page.</p></pre>residentbio: <pre><p>Thanks <a href="/u/synakx" rel="nofollow">/u/synakx</a> and <a href="/u/CaptaincCodeman" rel="nofollow">/u/CaptaincCodeman</a>, I see the light now. Thinking on doing some regex so it only redirects under /app/ folder, since I&#39;m fine with go handling any other 404. </p> <p>You rock!</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

548 次点击  
加入收藏 微博
0 回复
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传