Just started using SolidJS and solid router, already stuck at the route not rendering the component inside "element". Instead it's showing "[object Object][object Object]"
See:
https://codesandbox.io/s/solidjs-shopping-cart-wj5zvr?file=/src/App.jsx
Below is the code:
import { Router, Route } from "solid-app-router";
function Home() {
return <h1>Home page here...</h1>;
}
function Cart() {
return <h1>Cart page here...</h1>;
}
function App() {
return (
<>
<header>header...</header>
<Router>
<Route path="/" element={<Home />} />
<Route path="/cart" element={<Cart />} />
</Router>
<footer>footer..</footer>
</>
);
}
export default App;
Try going with <Route path="/" component={Home} /> instead.
That also makes it wasy to convert to lazy routes (for code splitting) in the future...
<Route path="/" component={lazy(() => import("./home"))} />
EDIT: I took a look at your codesandbox and noticed there is already <Router> in index.jsx so what you want in App.jsx is actually <Routes>...<Routes>.
<Routes>
<Route path="/" component={Home} />
<Route path="/cart" component={Cart} />
</Routes>
Related
my App component is rendering... but not PdfPage. When I interchange the components, PdfPage is rendering, but not App. Please help!
import React from 'react';
import ReactDOM from 'react-dom';
import { App} from './App';
import { PdfPage } from './PdfPage';
import { BrowserRouter as Router, Routes, Route} from 'react-router-dom';
const routing = (
<>
<Router>
<Routes>
<Route exact path="/" element={<App />} />
<Route path={"/pdfPage"} element={<PdfPage />} />
</Routes>
</Router>
</>
);
ReactDOM.render(routing, document.getElementById('root'));
I tried this code and it works perfectly. Just to be sure, are you accessing pdfPage by going to localhost:3000/pdfPage right?
I figured out the problem. It was not in the program. I had to edit my snowpack.config.js to enable routing
How can I control the shape of the extra item that is appended to a React Material-UI AvatarGroup (when the number of Avatars is more than max) so that it matches the rounded variant of the Avatars.
<AvatarGroup max={4}>
<Avatar
variant="rounded"
alt="Remy Sharp"
src="/static/images/avatar/1.jpg"
/>
<Avatar
variant="rounded"
alt="Travis Howard"
src="/static/images/avatar/2.jpg"
/>
<Avatar
variant="rounded"
alt="Cindy Baker"
src="/static/images/avatar/3.jpg"
/>
<Avatar
variant="rounded"
alt="Agnes Walker"
src="/static/images/avatar/4.jpg"
/>
<Avatar
variant="rounded"
alt="Trevor Henderson"
src="/static/images/avatar/5.jpg"
/>
</AvatarGroup>
API doc doesn't mention how to set this: https://material-ui.com/api/avatar-group/
Although the "next" version does: https://next.material-ui.com/es/api/avatar-group/
You can override the shape's style using a mui global class selectors:
import React from "react";
import Avatar from "#material-ui/core/Avatar";
import AvatarGroup from "#material-ui/lab/AvatarGroup";
import { createStyles, makeStyles, Theme } from "#material-ui/core/styles";
const useStyles = makeStyles((theme: Theme) =>
createStyles({
root: {
"& .MuiAvatar-root": { borderRadius: 0 }
}
})
);
export default function GroupAvatars() {
const classes = useStyles();
return (
<AvatarGroup max={4} className={classes.root}>
<Avatar
alt="Remy Sharp"
variant="rounded"
src="/static/images/avatar/1.jpg"
/>
<Avatar
alt="Travis Howard"
variant="rounded"
src="/static/images/avatar/2.jpg"
/>
<Avatar
alt="Cindy Baker"
variant="rounded"
src="/static/images/avatar/3.jpg"
/>
<Avatar
alt="Agnes Walker"
variant="rounded"
src="/static/images/avatar/4.jpg"
/>
<Avatar
alt="Trevor Henderson"
variant="rounded"
src="/static/images/avatar/5.jpg"
/>
</AvatarGroup>
);
}
please find a working example on codesandbox
New to Flutter,
I know below question can archive similar goal, but is any other easy way to do so?
how flutter work with single page web and different route url?
here is react example:
<Router>
<div>
<nav>
<ul>
<li>
<Link to="/">Home</Link>
</li>
<li>
<Link to="/about">About</Link>
</li>
<li>
<Link to="/users">Users</Link>
</li>
</ul>
</nav>
{/* A <Switch> looks through its children <Route>s and
renders the first one that matches the current URL. */}
<Switch>
<Route path="/about">
<About />
</Route>
<Route path="/users">
<Users />
</Route>
<Route path="/">
<Home />
</Route>
</Switch>
</div>
</Router>
);
Yeah, sure there is.
The point is that you would have to use an external package.
It's simple to use and you can pass state from URL and vice versa.
You would have to implement 2 methods, one for the URL to state and the other for the opposite.
SimpleUrlHandler(
urlToAppState: (BuildContext context, RouteInformation routeInformation) {
// This is called when a user enters a url or presses the forward/backward
// button. You should update your app state according to the RouteInformation.
},
appStateToUrl: () {
// This is called when the url should be updated
// You must return a RouteInformation
},
child: YourAppWidget(),
);
I add Switch router component to my project in order to set default page.
When i build it gives the following error:
Error: Failed exporting HTML for URL About (src\pages\About.js): Invariant failed
- tiny-invariant.cjs.js:11 invariant
[byte-artisan]/[tiny-invariant]/dist/tiny-invariant.cjs.js:11:11
- history.min.js:1 Object.createBrowserHistory
[byte-artisan]/[history]/cjs/history.min.js:1:3626
- react-router-dom.min.js:1 new t
[byte-artisan]/[react-router-dom]/cjs/react-router-dom.min.js:1:1036
- react-dom-server.node.production.min.js:33 c
[byte-artisan]/[react-dom]/cjs/react-dom-server.node.production.min.js:33:323
- react-dom-server.node.production.min.js:36 Sa
[byte-artisan]/[react-dom]/cjs/react-dom-server.node.production.min.js:36:1
- react-dom-server.node.production.min.js:41 a.render
[byte-artisan]/[react-dom]/cjs/react-dom-server.node.production.min.js:41:467
- react-dom-server.node.production.min.js:41 a.read
[byte-artisan]/[react-dom]/cjs/react-dom-server.node.production.min.js:41:58
- react-dom-server.node.production.min.js:53 renderToString
[byte-artisan]/[react-dom]/cjs/react-dom-server.node.production.min.js:53:83
- exportRoute.js:127 renderToStringAndExtract
[byte-artisan]/[react-static]/src/static/exportRoute.js:127:21
- exportRoute.js:191 renderToStringAndExtract
[byte-artisan]/[react-static]/src/static/exportRoute.js:191:15
- runtime.js:62 tryCatch
[byte-artisan]/[regenerator-runtime]/runtime.js:62:40
- runtime.js:288 Generator.invoke [as _invoke]
[byte-artisan]/[regenerator-runtime]/runtime.js:288:22
- runtime.js:114 Generator.prototype.(anonymous function) [as next]
[byte-artisan]/[regenerator-runtime]/runtime.js:114:21
- exportRoute.js:52 asyncGeneratorStep
[byte-artisan]/[react-static]/lib/static/exportRoute.js:52:103
- exportRoute.js:54 _next
[byte-artisan]/[react-static]/lib/static/exportRoute.js:54:194
- next_tick.js:68 process._tickCallback
internal/process/next_tick.js:68:7
This doesn't happen when running the site (npm run start).
More odd, happens only when build the site, for some pages. The pages affected changes every build even if i don't change anything between builds.
Here the router declaration:
App.js
import React from 'react'
import {
BrowserRouter as Router,
Route,
Link,
Switch,
Redirect
} from 'react-router-dom'
//pages
import './app.css'
import About from './pages/About'
function page404() {
return (
<div>
<h2>page404</h2>
</div>
);
}
function App() {
return (
<Router>
<div>
<ul className="menu-bar">
<li>
<Link to="/about">About</Link>
</li>
</ul>
<Switch>
<Route path="/About" component={About} />
<Route component={page404} />
</Switch>
</div>
</Router>
)
}
export default App
Environment: react-static v6.3.6
remove Router like this
function App() {
return (
<div>
<ul className="menu-bar">
<li>
<Link to="/about">About</Link>
</li>
</ul>
<Switch>
<Route path="/About" component={About} />
<Route component={page404} />
</Switch>
</div>
)
}
export default App
because react-static-plugin-react-router has already wrappered it with Router
I am learning MeteorJS, React and React-Router and I am having difficulty passing a parameter in the URL through the router. I have searched for the answer and I cannot find what I am doing wrong:
In my Routes.jsx file ('lists' is my MongoDB collection):
render: function() {
return (
<Router history={browserHistory}>
<Route path='/' component={Navbar}>
<Route path='/home' component={Home} />
<Route path='/register' component={Register} />
<Route path='/login' component={Login} />
<Route path='/listpages/:listId' component={ListPages} />
</Route>
</Router>
);
}
and in my MyLists.jsx file (inside the component):
renderLists() {
return this.data.lists.map((myList) => {
return
<li key={myList._id}>
<Link to='listpages' params={{ listId: myList._id}}>
{myList.name}
</Link>
</li>;
});
},
render() {
return (
<div>
<h2>Lists</h2>
<AddList />
<ul>
{this.renderLists()}
</ul>
</div>
);
}
When I click on one of the links for ListPages, I get the console error:
Warning: Location "listpages" did not match any routes
Also, the correct listId is embedded in the line item, but not the URL:
<li>
<Link to="listpages" params={listId: "qksabGvfeuf5PdaJv"} onlyActiveOnIndex=false...>
<a params={listId: "qksabGvfeuf5PdaJv" className="" style={}...>Inbox</a>
</Link>
</li>
But if I remove the parameter to this:
<Route path='/listpages' component={ListPages} />
then it works as expected and the contents of ListPages is displayed (right now it's only a heading to see if I get there). So ListPages does exists, but not when I pass the parameter. What am I doing wrong?
Thank you in advance for any help you can provide!
For anyone that may have stumbled upon this page doing a Google search:
This question may have been asked prior to the current version of React Router, but the correct way to do links with path='/route/:id' is to do <Link to={'/route/' + id} where the id is the thing you want to display. Since you're missing the key id part, you're getting an error.
For example, I want to show a table with a specific ID that I get as a prop.
Routes.jsx:
...
<Route path='/DisplayTable/:tableId' component={ Comp } />
...
Component I am going to display the table from (SelectTable.jsx):
...
<Link to={'/DisplayTable/' + this.props.tables[i]._id} />
...
You can pass your query parameter like this,
<Link to={{ pathname: 'listpages', query: { listId: myList._id } }}>
Thank you for the input. I made the change and the first time it loaded, I clicked the link and received the same error (Warning: Location "listpages" did not match any routes). When I refreshed to try it again, now the application crashes on startup with an unexpected token error on the line that you suggested.