Passing parameter with React-Router in Meteor - mongodb

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.

Related

is any easier way to build a single web page like react in flutter

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(),
);

How to insert a Link into a GridListTile in Gatsby

I am trying to have a clickable grid of images within Gatsby using the Material-UI GridList
Inside the GridListTile I am not able to put a Gatsby Link around my image or inside the GridListTileBar.
export default function SingleLineGridList() {
const classes = useStyles();
return (
<div className={classes.root}>
<GridList className={classes.gridList} cols={1.5} cellHeight="300">
{tileData.map(tile => (
<GridListTile key={tile.img} className={classes.gridListTile}>
<Link to={`product/1`}>
<img src={tile.img} alt={tile.title} />
</Link>
<GridListTileBar
title={tile.title}
classes={{
root: classes.titleBar,
title: classes.title,
}}
/>
</GridListTile>
))}
</GridList>
</div>
);
}
I get the error 'TypeError: Cannot read property 'muiName' of undefined'
I have found similar examples from straight react so presume it is something to do with the Gatsby link component
I realise it is likely to have something to do with component wrapping but have no idea how to implement this.
How can I make the Gatsby Link element an accepted element with the GridListTile?

Error: Failed exporting HTML for URL About (src\pages\About.js): Invariant failed

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

Polymer 1.x: Modal paper-dialog appears behind its backdrop

Does anybody have any advice for fixing the problem of a modal appearing behind its backdrop?
So far, I have tried making sure I have all the necessary imports (including <paper-dialog-scrollable>).
I also tried a "hack-fix" (suggested by someone) involving setting z-index: auto in the css of paper-header-panel. Neither works.
It's worth noting that the <paper-dialog> tag works just fine. Until I add the modal attribute.
Any ideas?
Similar issues
Appearing around the internet are this issue report and this Stackoverflow question.
my-element.html
<script src="http://www.polymer-project.org/1.0/samples/components/webcomponentsjs/webcomponents-lite.js"></script>
<link rel="import" href="http://www.polymer-project.org/1.0/samples/components/polymer/polymer.html" />
<link rel="import" href="../../../bower_components/paper-dialog/paper-dialog.html">
<dom-module id="example-element">
<template>
<!-- Dialog -->
<paper-dialog id="contactDialog" modal>
<h2>Login</h2>
<paper-dialog-scrollable>
<form id="contact-form" autofocus>
<paper-input autofocus id="name" label="Your Name"></paper-input>
<paper-input id="email" label="Email Address"></paper-input>
</form>
</paper-dialog-scrollable>
<div class="buttons">
<paper-button dialog-dismiss>Cancel</paper-button>
<paper-button dialog-confirm>Accept</paper-button>
</div>
</paper-dialog>
<!-- Button -->
<paper-button id="login"
data-dialog="contactDialog"
on-tap="openDialog">Login</paper-button>
</template>
</dom-module>
<script>
(function() {
Polymer({
is: 'example-element',
properties: {...},
openDialog: function(){
this.$.contactDialog.open();
}
});
})();
</script>
This is my solution:
openDialog: function(){
var body = document.querySelector('body');
Polymer.dom(body).appendChild(this.$.dialogId);
this.$.dialogId.open();
}
Special Note: This answer applies to those trying to implement a <paper-dialog modal> element inside a header element. Specifically, inside <paper-drawer-panel>.
Answer:
On this bug report rubenstolk provides a hack-fix as follows:
To implement #dhpollack's hack in a nice way, add this function to your custom element:
// https://github.com/PolymerElements/paper-dialog/issues/7
patchOverlay: function (e) {
if (e.target.withBackdrop) {
e.target.parentNode.insertBefore(e.target.backdropElement, e.target);
}
},
And add on-iron-overlay-opened="patchOverlay" to all your <paper-dialog>'s
I have tested it and verifies that it works. So for now, that solves it. Therefore, I suppose it is sufficient for now to wait until the bug is fixed.
It wasn't quite clear from the screenshot, but the problem is your modal dialog appears behind the <paper-drawer-panel>, yes?
If so, I believe the solution is the same here: just place the dialog or custom element containing the dialog outside of the <paper-drawer-panel>, e.g.:
<paper-drawer-panel>
<paper-header-panel drawer>
<paper-toolbar>
<div>Drawer</div>
</paper-toolbar>
<paper-menu selected="{{_selected}}">
<paper-item>Item 1</paper-item>
<paper-item>Item 2</paper-item>
</paper-menu>
</paper-header-panel>
<paper-header-panel mode="standard" main>
<paper-toolbar>
<h1>[[_selected]]</h1>
</paper-toolbar>
<neon-animated-pages selected="{{_selected}}">
<paper-button raised on-tap="openDialog">Show Dialog</paper-button>
<div>Div</div>
</neon-animated-pages>
</paper-header-panel>
</paper-drawer-panel>
<example-element id="dialog"></example-element>
Here is a screenshot illustrating this:

How to include partials using ng-include(AngularJS) in IBM Websphere Portlet

I am using ng-include directive to include partial views in IBM websphere Portlet.The code snippet is below
1.Defining render URL
<portlet:defineObjects />
<portlet:renderURL var="resourceURL" windowState="MINIMIZED" portletMode="view">
<portlet:param name="jspPage" value="/partials/list.html" />
</portlet:renderURL>
2.Main.js
<script>
var myApp = angular.module("App", []);
myApp.controller("myCtrl", function ($scope )
{
$scope.page='<%=resourceURL%>';
});
</script>
3.Home.jsp
<div id="<portlet:namespace />main" data-ng-app="App" data-ng-controller="myCtrl" >
<div ng-include src="'page'"></div>
<div>
But the partials are not included. Can anyone suggest me how to fix this?Am i missing anything?
You would need to change your code to go to the portlet context path:
Replace:
<%=resourceURL%>
with
<%=renderResponse.encodeURL(renderRequest.getContextPath():%>
This will work:
<div ng-include="'<%= renderResponse.encodeURL(renderRequest.getContextPath() + "/scripts/mypage.tpl.html") %>'"></div>