Angular dart bookmarking views

旧时模样 提交于 2019-12-10 15:53:34

问题


It is my experience that Angular Dart is agnostic to your backend server implementation. it doesn't care if your server is in java, ruby or whatever. Angular dart has the concept of views and has a module that deals with routing between them. these routes also modify the address bar of the browser when it changes views.

I have come across this issue. Though the angular router module will change the address bar, because said route doesn't actually exist as far as the backend server is concerned, and as such will always issue a 404 response.

If such is the case, then I find the ability to route to different pages via angular to be pointless. Might as well I code in a more traditional server oriented fashion to transition between pages, than to sue angular.

Is it that there is something that is missing? Is there a way you can can get your server to resolve to the correct angular page?


回答1:


You can use usePushState: false then only the (client) local part of the URL is changed.
see https://github.com/angular/angular.dart.tutorial/blob/master/Chapter_06/web/main.dart#L27
This part after the hash is never sent to the server.
This might cause some additional work for SEO.

http://example.com/index.html#someRoutePath/anotherRoutePath

or you can configure your server in a way that each request is handled independent of the path in the request and use the route package server side too.

see also https://stackoverflow.com/a/17909743/217408




回答2:


You can configure your backend server to point all routes to the same file (using some kind of wildcard route which all decent servers should support). So app/some/page and app/another/page would both be served app.html. Then on your app startup you could have Angular parse the URL of the page, and manually route to that page.

I have used this approach with a Polymer app (with the Route library) and it works great. It should work similarly for Angular.



来源:https://stackoverflow.com/questions/25329525/angular-dart-bookmarking-views

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