首页 \ 问答 \ 服务器端的react-router没有同构(server-side react-router without being isomorphic)

服务器端的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
更新时间:2023-08-05 11:08

最满意答案

与克里斯泰勒的答案类似,你可以这样做:

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.

相关问答

更多
  • 如果你真的想确保你的一些变量的范围有限,并且你想避免调用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 ...
  • 不确定你要做什么,但是让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 ...
  • 你是否意识到你做了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 ...
  • 如果你想将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指南 指南基本上只是创建无花果的工具。 文件。 所有你可以用指南做的,你可以自己编程。 创建ui-elements手工就像使用指南一样简单(我实际上更喜欢以编程方式创建gui元素,因为我认为指南的编码非常差)... 每个guide-elements都有它的回调,必须在某处编码,通常(我认为100%的时间)fig文件与.m文件具有相同的名称。 找到相应的.m -file并转到你所关注的回调。在那里你可以像在任何其他代码中一样简单地放置断点。 注意:您甚至可以更改代码而无需重新打开图形文件! F ...
  • 一个例子: >> 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

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)