S
SolidJS2d ago
finn

SolidJS Router Missunderstanding

Can someone help me setup a basic router with the "@solidjs/router" I am not sure where to put what. My current understanding was that this is the way to do but document.getElementById is underlined red:
Argument of type 'HTMLElement | null' is not assignable to parameter of type 'MountableElement'.
Type 'null' is not assignable to type 'MountableElement'
Argument of type 'HTMLElement | null' is not assignable to parameter of type 'MountableElement'.
Type 'null' is not assignable to type 'MountableElement'
App.tsx
import type { Component } from 'solid-js';
import { render } from "solid-js/web";
import { Router, Route } from "@solidjs/router";

import logo from './logo.svg';
import styles from './App.module.css';

const App: Component = () => {
return (
<div class={styles.App}>
<header class={styles.header}>
<img src={logo} class={styles.logo} alt="logo" />
<p>
Edit <code>src/App.tsx</code> and save to reload.
</p>
<a
class={styles.link}
href="https://github.com/solidjs/solid"
target="_blank"
rel="noopener noreferrer"
>
Learn Solid
</a>
</header>
</div>
);
};

render(
() => <Router root={App}>
{
/*... routes */
}</Router>,
document.getElementById("app")
);

export default App;
import type { Component } from 'solid-js';
import { render } from "solid-js/web";
import { Router, Route } from "@solidjs/router";

import logo from './logo.svg';
import styles from './App.module.css';

const App: Component = () => {
return (
<div class={styles.App}>
<header class={styles.header}>
<img src={logo} class={styles.logo} alt="logo" />
<p>
Edit <code>src/App.tsx</code> and save to reload.
</p>
<a
class={styles.link}
href="https://github.com/solidjs/solid"
target="_blank"
rel="noopener noreferrer"
>
Learn Solid
</a>
</header>
</div>
);
};

render(
() => <Router root={App}>
{
/*... routes */
}</Router>,
document.getElementById("app")
);

export default App;
2 Replies
jer3m01
jer3m012d ago
add a ! after getElementById()
document.getElementById("app")!
document.getElementById("app")!
finn
finnOP2d ago
and is there anything else I need to add/modify? or just assign routes now in that render method
import type { ParentComponent } from "solid-js";
import { render } from "solid-js/web";
import { Router, Route } from "@solidjs/router";

import Home from "./routes/Home";
import Test from "./routes/Test";

const App: ParentComponent = (props) => (
<>
<h1>Root header</h1>
{props.children}
</>
);

render(
() => (
<Router root={App}>
<Route path="/" component={Home} />
<Route path="/test" component={Test} />
</Router>
),
document.getElementById("app")!
);

export default App;
import type { ParentComponent } from "solid-js";
import { render } from "solid-js/web";
import { Router, Route } from "@solidjs/router";

import Home from "./routes/Home";
import Test from "./routes/Test";

const App: ParentComponent = (props) => (
<>
<h1>Root header</h1>
{props.children}
</>
);

render(
() => (
<Router root={App}>
<Route path="/" component={Home} />
<Route path="/test" component={Test} />
</Router>
),
document.getElementById("app")!
);

export default App;
This is my current version which just gives me a white page Figured it out thanks for your help :)

Did you find this page helpful?