我希望能够为某些路由使用相同的路由器插座.
路由设置(简化):
export const routes: Routes = [
{
path: 'app', component: AppComponent,
children: [
path: 'category/:id', component: CategoryComponent,
children: [
{ path: 'post/:id', component: PostComponent }
]
]
}
];
Run Code Online (Sandbox Code Playgroud)
例如,我们有这条路径:
/app/category/1/post/1
Run Code Online (Sandbox Code Playgroud)
那打破了
/app - AppComponent
|_ /catory/1 - CategoryComponent
|_/post/1 - PostComponent
Run Code Online (Sandbox Code Playgroud)
该AppComponent有<router-outlet>哪些渲染CategoryComponent,也应该呈现的PostComponent时候这条路线是有效的.
这类问题的常见答案:
移动子路由并将其添加到app-route children数组中
不,这不是正确的方法.我们仍然需要我们的路线层次结构.CategoryComponent可能知道PostComponent没有的东西- 比如Breadcrumb命名
所以我们仍然希望我们的CategoryComponent加载.(即使它的视图不是渲染)
使用<router-outlet>内部CategoryComponent
否.CategoryComponent不应该负责它自己的<router-outlet>.本PostComponent应在地方的渲染CategoryComponent,并添加CSS来放置它这样应该是非法的.
我怎样才能实现这种行为?
我需要编写自己的路由器插座吗? …
可能重复:
我可以将大量位图保存到一个位图吗?(2d)的
我想知道canvas.save和canvas.restore是如何工作的.
我希望它如何工作,以及我如何使用它(但不起作用).
我真正需要的是在某个阶段(背景)保存我的画布,然后在它上面绘制对象,而不必每次我想要更新我的画布时绘制背景.
可以说我有这个帮手 application_helper.rb
def my_helper(content = nil, *args, &block)
content_tag(:div, class: :my_wrapper) do
(block_given? ? yield : content) + content_tag(:span, "this is the end", *args)
end
end
Run Code Online (Sandbox Code Playgroud)
我从一个视角来称呼它
my_helper do
content_tag(:div, "this is the beginning")
end
Run Code Online (Sandbox Code Playgroud)
我希望结果是这样的
<div class="my_wrapper">
<div>
this it the beginning
</div>
<span>
this is the end
</span>
</div>
Run Code Online (Sandbox Code Playgroud)
但实际上,带有"这就是结束"的文本的范围不会附加到收益率上.
如果我在帮助器中使用此行:
(block_given? ? content_tag(:div, &block) : content) + content_tag(:span, "this is the end", *args)
Run Code Online (Sandbox Code Playgroud)
我会得到两个内容,但收益率将包含在另一个div中.
如何在收益后添加/追加内容,而不将收益率包含在不同的content_tag中?