summaryrefslogtreecommitdiff
path: root/@linaria/examples/Preact/preact-example/src/components/app.js
diff options
context:
space:
mode:
Diffstat (limited to '@linaria/examples/Preact/preact-example/src/components/app.js')
-rw-r--r--@linaria/examples/Preact/preact-example/src/components/app.js43
1 files changed, 43 insertions, 0 deletions
diff --git a/@linaria/examples/Preact/preact-example/src/components/app.js b/@linaria/examples/Preact/preact-example/src/components/app.js
new file mode 100644
index 0000000..03b0292
--- /dev/null
+++ b/@linaria/examples/Preact/preact-example/src/components/app.js
@@ -0,0 +1,43 @@
+import { h, Component } from 'preact';
+import { Router } from 'preact-router';
+
+import Header from './header';
+
+import { css } from 'linaria';
+import { styled } from 'linaria/react';
+
+// Code-splitting is automated for routes
+import Home from '../routes/home';
+import Profile from '../routes/profile';
+
+const Background = styled.div`
+ background-color: aliceblue;
+`;
+
+const bluishText = css`
+ color: cornflowerblue;
+`
+
+export default class App extends Component {
+
+ /** Gets fired when the route changes.
+ * @param {Object} event "change" event from [preact-router](http://git.io/preact-router)
+ * @param {string} event.url The newly routed URL
+ */
+ handleRoute = e => {
+ this.currentUrl = e.url;
+ };
+
+ render() {
+ return (
+ <Background class={bluishText} id="app">
+ <Header />
+ <Router onChange={this.handleRoute}>
+ <Home path="/" />
+ <Profile path="/profile/" user="me" />
+ <Profile path="/profile/:user" />
+ </Router>
+ </Background>
+ );
+ }
+}