服务器端的react-router没有同构(server-side react-router without being isomorphic)
在我的网络应用程序中,我不想使用基于散列的路由,我不希望看到任何
#
出现在我的URL中。 我想使用RESTful URL,例如http://www.example.com/blog/id 。
react-router
可以很好地处理客户端路由,但如果用户在浏览器地址栏上输入或刷新页面,请求将被发送到Web服务器,然后Web服务器必须了解URL和句柄路由。Isomorphic是一种很好的解决方案,因为它可以在客户端和服务器端呈现任何页面。 实际上,在Github上有许多反应入门套件项目声称是同构的。
在我看来,同构看起来很漂亮,但编写代码太昂贵了:你需要让你在客户端和服务器端成功地对组件进行渲染,这需要开发人员付出巨大的努力。
所以这是我的问题,我可以让react-router同构,而不是整个代码吗?
In my web app, I don't want to use hash-based routing, I don't want to see any
#
appear in my URLs. I want to use RESTful URLs, e.g., http://www.example.com/blog/id.
react-router
can deal with client-side routing quite well, but if a user hit enter on the browser address bar or refresh the page, the request will be sent to the web server and then the web server has to understand the URL and handle the routing.Isomorphic is a good solution to this situation since it can render any page on both client-side and server-side. Actually there are many react starter kit projects on Github which claim to be isomorphic.
In my opinion, isomorphic looks beautiful but it's too expensive to write code: you need to make you react components render successfully both on client-side and server-side, which needs developers to make great efforts.
So here is my question, can I just make the react-router be isomorphic, not the entire code?
原文:https://stackoverflow.com/questions/34101549
最满意答案
与克里斯泰勒的答案类似,你可以这样做:
function [ output ] = Enumerate( items ) output = struct('Index',num2cell(1:length(items)),'Value',num2cell(items)); end items = [3,14,15,92]; for item = Enumerate(items) item.Index item.Value end
枚举函数需要一些更多的工作才能成为通用目标,但这是一个开始,并为您的示例起作用。
这对于小载体来说可以,但是你不想用任何可观的载体来做到这一点,因为性能会成为问题。
Similar to Chris Taylor's answer you could do this:
function [ output ] = Enumerate( items ) output = struct('Index',num2cell(1:length(items)),'Value',num2cell(items)); end items = [3,14,15,92]; for item = Enumerate(items) item.Index item.Value end
The Enumerate function would need some more work to be general purpose but it's a start and does work for your example.
This would be okay for small vectors but you wouldn't want to do this with any sizable vectors as performance would be an issue.
相关问答
更多-
Matlab,在循环执行后自动删除索引变量(Matlab, automatically delete the index variable after the execution of a loop)[2023-05-07]
如果你真的想确保你的一些变量的范围有限,并且你想避免调用clear ,你可以使用嵌套函数 。 请注意,这可能无助于提高可读性,而且它比打电话clear 更高 。 但是,它确实确保主函数工作空间中的唯一变量是您想要/需要保留的变量。 function doSomething List = [1 2 3 4] ; runLoopOnList() %# some other code here %# nested functions function runLoopOnList ... -
与克里斯泰勒的答案类似,你可以这样做: function [ output ] = Enumerate( items ) output = struct('Index',num2cell(1:length(items)),'Value',num2cell(items)); end items = [3,14,15,92]; for item = Enumerate(items) item.Index item.Value end 枚举函数需要一些更多的工作才能成为通用目标,但这是一个开始, ...
-
不确定你想要实现什么,但我认为你可以修复你的循环如下: entries = 3; X =zeros(20,1); for ni = 1:entries n = input('Determine value for case :'); X(n) = input('Determine position:'); end Not sure exactly what you are trying to achieve, but I think that you can fix ...
-
基本的Matlab FOR功能(Basic Matlab FOR function)[2021-11-08]
不确定你要做什么,但是让X循环依赖于X东西会让事情变得不那么清晰(并且可能不会像你期望的那样工作)。 请注意, for循环的常规语法是: for t = startpoint:increment:endpoint % do stuff % You can read here from t, startpoint,increment,endpoint but not update them end Not sure what you are trying to do, but letting X ... -
MATLAB循环具有不同的值(MATLAB loop with different value)[2023-10-25]
你是否意识到你做了4次同样的事情? 这就是为什么你没有得到新的价值,没有。 你的代码做了: test_main(1)我假设为1,否则你没有显示所有输出。 随机创建 if w<0.5 ...... 调用test_sub(status) 这里,第一件事是for variable = 1:4 ,或“重复一切4次” 对于相同的status重复disp 4次 出。 为什么test_sub函数中有for循环? 该函数应该测试结果,并且只应该这样做。 它应该看起来像: function[a] = test_sub(z,c ... -
根据你的评论,我建议使用单元阵列 。 这允许通过索引存储任何类型的结果。 例如: foo=cell(bar,1); for ii=1:bar foo{ii}=quux; end 然后,您可以保存foo以保留所有中间结果。 尽管循环索引不会根据您的需要烘焙到变量名称中,但它提供了相同的功能。 Based on your comment, I suggest using a cell array. This allows any type of result to be stored by index ...
-
如果您计划索引至k+3则不应该让k始终保持length(data) 。 我还冒昧地大大简化了你的代码,但随时忽略它! for k = 1:length(data)-3 % maximum k = length(data)-3, so maximum index = length(data)-3+3=length(data) index = k:k+3; cur_data = data(k:k+3); % Interweaving the data q = cur_da ...
-
在matlab中进行循环(for loop in matlab)[2023-11-03]
如果你想将vector所有值传递给for循环中的函数somefunt ,你可以使用vector作为循环值,如下所示: for i = vector somefunt(i); end 这相当于: somefunt(20); somefunt(30); somefunt(60); ... If you want to pass all the values in vector to your function somefunt in a for loop, you can just use vector ... -
对于Matlab指南中的循环(For Loop within Matlab GUIDE)[2023-03-21]
使用Matlab指南 指南基本上只是创建无花果的工具。 文件。 所有你可以用指南做的,你可以自己编程。 创建ui-elements手工就像使用指南一样简单(我实际上更喜欢以编程方式创建gui元素,因为我认为指南的编码非常差)... 每个guide-elements都有它的回调,必须在某处编码,通常(我认为100%的时间)fig文件与.m文件具有相同的名称。 找到相应的.m -file并转到你所关注的回调。在那里你可以像在任何其他代码中一样简单地放置断点。 注意:您甚至可以更改代码而无需重新打开图形文件! F ... -
考虑到matlab中的索引,如何最好地遍历数组?(how best to loop through an array taking into account of the index in matlab?)[2022-06-25]
一个例子: >> x = randi(10, [1 5]) x = 9 7 4 10 1 >> x.^(1:numel(x)) ans = 9 49 64 10000 1 An example: >> x = randi(10, [1 5]) x = 9 7 4 10 1 >> x.^(1:numel(x)) ans = 9 49 64 10000 1