Routes in DART, s server required?

Deadly 提交于 2019-12-12 01:57:39

问题


I tried both AngularDART routes, and routes with Polymer, this example

but found, that none is working once I open the file from Dartium directly, but both work perfectly once I run them from Dart editor!

am I doing something wrong!

thanks


回答1:


This is because when you run from DartEditor (Ctrl+R) pub serve is launched which acts as a web server for the browser. This doesn't mean that you need a web server to run this example though.
What makes the difference is that pub serve runs transformers that do some sorts of code modification on the fly when the browser requests a page from the server.

When you run pub build (or pub build example when the code is not in web directory) this code modifications (and some more like tree-shaking and minification) are applied and you can open the resulting output (from build/example/example_01.html) directly without a server using a file URL.




回答2:


I think the point is both using "import html" file, which can run with web server and some browsers,, for example route run smoothly at Safari browser without web server, but did not run without server at Chrome, and Chrome shows this error msg:

Imported resource from origin 'file://' has been blocked from loading by 
Cross-Origin Resource Sharing policy: Received an invalid response. Origin 'null'
is therefore not allowed access.


来源:https://stackoverflow.com/questions/25247743/routes-in-dart-s-server-required

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!