SPA
This commit is contained in:
parent
c51dd48a73
commit
937b9fb48f
9 changed files with 180 additions and 90 deletions
|
|
@ -15,27 +15,6 @@ using namespace Crafter::CppDOMBindings;
|
|||
|
||||
HtmlElementView* blogButton;
|
||||
|
||||
void RenderRoot(const std::string_view route) {
|
||||
std::string pageContent;
|
||||
if(route == "/blog") {
|
||||
pageContent = RenderBlog();
|
||||
} else {
|
||||
pageContent = RenderBlog(); //default route
|
||||
}
|
||||
// Set body content
|
||||
main->SetInnerHTML(pageContent);
|
||||
|
||||
// Update active nav link
|
||||
// auto navLinks = document->GetElementsByClassName("nav-container")[0]->GetElementsByTagName("a");
|
||||
// for(auto link : navLinks) {
|
||||
// if(link->GetAttribute("id") == "blog-nav-button") {
|
||||
// link->SetAttribute("class", "active");
|
||||
// } else {
|
||||
// link->SetAttribute("class", "");
|
||||
// }
|
||||
//}
|
||||
}
|
||||
|
||||
int main() {
|
||||
AddPopStateListener([]() {
|
||||
RenderRoot(GetPathNameString());
|
||||
|
|
@ -44,7 +23,7 @@ int main() {
|
|||
blogButton = new HtmlElementView("blog-nav-button");
|
||||
blogButton->AddClickListener([](Crafter::MouseEvent e) {
|
||||
PushState("{}", "", "/blog");
|
||||
RenderRoot("blog");
|
||||
RenderRoot("/blog");
|
||||
});
|
||||
|
||||
RenderRoot("/");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue